tags:

views:

90

answers:

1

Hi, I am using the following query to display database rows in an alphabetical order:

SELECT word_id FROM table1 ORDER BY word ASC

But I want to get values from table2, where I don't have column "word" and to sort it by column "word" which is in table1.

I want something like this:

SELECT word_id FROM table2 ORDER BY table1.word ASC

Thank you in advance.

+4  A: 

You must connect the two tables with a join:

SELECT t2.word_id
FROM table2 t2
   , table1 t1
WHERE t2.word_id = t1.word_id  -- this is the join
ORDER BY t1.word ASC
Aaron Digulla