Michael DePhillips wrote:

Hi,

Does anyone have a clever way of returning; a requested value with one value less than that value, and one value greater than that value with one query.

For example T1 contains

ID
1234
1235
1236
1238


Assuming the id's are consecutive.

You want surounding rows returned if the target Id is missing:
-----------------------------------------------------------------------------------------------------
select id from T1 as first where T1.id  between  (1237 -1) and (1237 +1);

You want no rows returned if the target Id is missing:
-------------------------------------------------------------------------------------
select id from T1 as first , inner join T2 as second on second.id between (first.id -1) and (first.id +1)
where first.id = 1237;

If you Id's aren't always consecutive, or you need something more smart post again.


Nigel

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to