In message <[EMAIL PROTECTED]>, James
Keeline <[EMAIL PROTECTED]> writes
>--- Emily Berk <[EMAIL PROTECTED]> wrote:
>
>> Let's say I have a set of records and I want to retrieve the first and the
>> last (ordered by, say, the value of one of the columns).
>> 
>> Is there 
>> 
>> To get either the first or the last, I'm assuming I would
>> 
>> Select * order by columnX ASC LIMIT 1 
>> 
>> and to get the last I'd order descending.
>> 
>> But how would I get both the first and the last in one query?  
>> 
>> Emily Berk
>> http://www.armadillosoft.com
>
>You could UNION the two queries:
>
>SELECT * ORDER BY columnX ASC LIMIT 1
>UNION
>SELECT * ORDER BY columnX DESC LIMIT 1;
>
>James Keeline

I tried this, because I have something similar that I need - "show me
the next and previous record WHERE... "

But I can't get your example to work, I get the error message
"Incorrect usage of UNION and ORDER BY"

The full SQL command that I am using is
SELECT * from sales ORDER BY salID ASC LIMIT 1 
UNION 
SELECT * from sales ORDER BY salID DESC LIMIT 1; 

Have I done something silly?

-- 
Pete Clark

Reply via email to