On May 22, 2004, at 2:25 AM, Darren Duncan wrote:

At 10:23 PM -0700 5/21/04, Sanford Selznick wrote:
I have Table1:
data1
data2
data3
nameID -> id of record in Table2

I have Table2
id
name1
name2

I'd like to select all records from table 1, and have them sorted by name1.

What's the best way to do this?

Try this:

SELECT t1.*
FROM Table1 t1 INNER JOIN Table2 t2 ON t2.id = t1.nameID
ORDER BY t2.name1

Does that work for you?

However, the above solution does not output the column you are sorting by, so what practical good does this sorting do you?

Also, all records in data1 which have the same nameID value will be unsorted within themselves, if that matters.

-- Darren Duncan

so, why not do

SELECT t1.data1, t1.data2, t1.data3, t1.nameID, t2.name1
FROM Table1 t1 INNER JOIN (or possibly LEFT JOIN depending on the constraint) Table2 t2
ON t1.nameID = t2.id
ORDER BY t2.name1, t1.(any other field), etc.



--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to