Jump to content

order by - using two different tables


liamoco

Recommended Posts

I want to list all users by name but also by status for example

 

Bob Charles - Online

Bob Jones - Online

Bob Back - Away

 

but my names and status are in two different tables

 

I order my names using ORDER BY fname, lname ASC // table name = users

I order my status using ORDER BY FIELD(status, 'online', 'away', 'busy') //table name = user_info

 

How can I do this?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/
Share on other sites

yes, this is what I have tried, not quite working, cannot get the join working, the field name status is from a different table called user_assign

 

$query_online = mysql_query("SELECT id, fname, mname, lname FROM users JOIN chat_assign ON status WHERE id in ('" . implode("', '", $friend_id_array) . "')  ORDER BY status, fname, lname");

 

solved with this...

 

$query_online = mysql_query("SELECT users.fname, users.mname, users.lname, chat_assign.status 
						FROM users, chat_assign
						WHERE (users.id = chat_assign.user_id) AND users.id in ('" . implode("', '", $friend_id_array) . "')
						ORDER BY FIELD(chat_assign.status, 'online', 'busy', 'away'), users.fname, users.lname
						");

 

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.