I have a table that contains a foreign key that can be null. When I do a search I want to have the matches that are null appear first, and then all other values sorted by another column. My data looks like this:

id      name
null    abc
1       def
2       xyz
null    zzz
7       aaa

I want to get them in this order:

null    abc
null    zzz
7       aaa
1       def
2       xyz

SELECT id, name FROM mytable ORDER BY ??

doing "ORDER BY id, name" will make the null values appear first, but then the following values will be in the wrong order. I've thought about using FIELD() in the order by, but the docs say it doesn't like nulls. Is there some other sorting mechanism I could use?

Thanks,

Marcus
--
Marcus Bointon
Synchromedia Limited: Putting you in the picture
[EMAIL PROTECTED] | http://www.synchromedia.co.uk


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

Reply via email to