webBoi
12-11-2009, 07:36 PM
I have a MySQL database table with columns:
FirstName (varchar)
LastName (varchar)
Organization (varchar)
RecordType (P=personal,O=organizational)
Some of the records in it are just organizations that don't have first or last names associated. Other records are just people with no organization. In search results, I want to offer a "display name" column that will be either the full name or organization name (another field denotes the record type). But I need to be able to order by EITHER column, depending on which is the record type.
So my query might look like:
SELECT *
FROM MyTable
WHERE [search criteria]
ORDER BY [LastName ASC,FirstName ASC ---OR--- Organization ASC... depending on value of RecordType for this particular record]
Does this make sense? Anybody know how this can be accomplished?
FirstName (varchar)
LastName (varchar)
Organization (varchar)
RecordType (P=personal,O=organizational)
Some of the records in it are just organizations that don't have first or last names associated. Other records are just people with no organization. In search results, I want to offer a "display name" column that will be either the full name or organization name (another field denotes the record type). But I need to be able to order by EITHER column, depending on which is the record type.
So my query might look like:
SELECT *
FROM MyTable
WHERE [search criteria]
ORDER BY [LastName ASC,FirstName ASC ---OR--- Organization ASC... depending on value of RecordType for this particular record]
Does this make sense? Anybody know how this can be accomplished?