Page 1 of 1

MySQL Query (ORDER BY other table)

Posted: Sun Dec 04, 2011 1:50 pm
by Hermit TL
I want to ORDER a query based on a value in a different table.
For example, say the query is

Code: Select all

SELECT links FROM table1
I have another table with a column that holds only a 1 or a 0. So how would I order it by that columns? (the linkname column is the same in both tables)
Anyone know how to do this?

Re: MySQL Query (ORDER BY other table)

Posted: Sun Dec 04, 2011 2:06 pm
by twinedev
You will need to do a join something like:

Code: Select all

SELECT t1.`links` 
FROM `table1` AS t1 
JOIN `table2` AS t2 
  ON t1.`linkname`=t2.`linkname` 
ORDER BY t2.`othercolumn`