[thelist] Q on SQL 'ORDER BY' - part 2

Hassan Schroeder hassan at webtuitive.com
Sun Apr 11 09:44:02 CDT 2004


jsWalter wrote:

> What I'm wanting to do is sort by NAME, and if NAME is empty, then by TITLE.

Here's an abbreviated example using `IF` --

SELECT
	IF(contacts.con_name = '',contacts.con_title,contacts.con_name)
AS
	either
FROM
	contacts
ORDER BY
	either

You can add back in the other fields :-) and of course adjust if the
name field defaults to NULL rather than an empty string, etc...

HTH!
-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.




More information about the thelist mailing list