Jump to content

order by - using two different tables


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
						");

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.