Jump to content

JOIN AND ORDER BY


Clinton

Recommended Posts

Currently I have a query set to do a search based upon no TimeOut and for a particular location using the $tablename table. That looks like:

 

$query = "SELECT * FROM $tablename WHERE TimeOut = '0000-00-00 00:00:00' AND Location = '$location'";

 

This ^ works just fine.

 

Now, one of the columns in $tablename is Position. In a different table ($tabletwo) I have a table that lists the same positions and an associated rank (a Manager would be 1, a Supervisor 2, Worker 3, etc.).

 

So in both tables, the common denominator is the Position/Positions column.

 

I would like to order the results based upon the column Position(s) using the rank established in $tabletwo (so individuals identified as Manager would be shown near the top instead of scattered throughout).

 

I can't seem to figure this out. I tried:

 

SELECT * FROM $tablename WHERE TimeOut = '0000-00-00 00:00:00' AND Location = '$location' as t1 LEFT JOIN $tabletwo AS t2 on t1.Position = t2.Positions ORDER BY t2.Rank

 

amongst about a hundred other things and can't seem to get it to work.

 

Any help would be appreciated.

 
 

Link to comment
https://forums.phpfreaks.com/topic/275808-join-and-order-by/
Share on other sites

where table two only holds the info as to what rank what position has...

 

 

SELECT * 
FROM $tablename  as t1
LEFT JOIN $tabletwo AS t2 
on t1.Position = t2.Positions
WHERE t1.TimeOut = '0000-00-00 00:00:00' 
AND t1.Location = '$location'
ORDER BY t2.Rank DESC
 

and this doesnt work?

Link to comment
https://forums.phpfreaks.com/topic/275808-join-and-order-by/#findComment-1419302
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.