MySQL Forums
Forum List  »  Newbie

Re: compound ID field, getting next and previous compound ID from table
Posted by: Rick James
Date: February 26, 2009 09:58PM

That gets messy.
If they were strings, you could do something like
ORDER BY CONCAT_WS(' ', id1, id2, id3)

But with numbers, let me do it for just 2 ids, and the 'next':
SELECT id1, id2
   FROM tbl
   WHERE (id1 = $id1 AND id2 > $id2)
      OR (id1 > $id1)
   ORDER BY id1 ASC, id2 ASC;

This is a compelling reason not to split a DATETIME in to two columns (a DATE and a TIME) if you are going to order things.

I'll let you extrapolate.

Options: ReplyQuote


Subject
Written By
Posted
Re: compound ID field, getting next and previous compound ID from table
February 26, 2009 09:58PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.