Gossamer Forum
Home : General : Databases and SQL :

ORDER BY question

Quote Reply
ORDER BY question
I have a stupid little problem:

I have two fields in my database, studio and name. Studio can be emtpy, name can't. The sort order I want is the following: first all entries where studio is not empty, those sorted by studio ASC. Second all entries where studio is empty, those sorted by name ASC.

The problem is that if I do ORDER BY studio ASC, name ASC, it will put the entries with empty studio fields first, the rest is OK.

Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Jul 6, 2002, 4:44 AM
Quote Reply
Re: [yogi] ORDER BY question In reply to
Your going to need to do two queries:

SELECT * FROM Table WHERE Studio <> "" ORDER BY Studio ASC
SELECT * FROM Table WHERE Studio = "" ORDER BY Name ASC

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] ORDER BY question In reply to
Thanks a lot. This does precisely what I want.

Ivan
-----
Iyengar Yoga Resources / GT Plugins