Monday 15 April 2013

php - Two Tables & Ordering By Column Not in Both -



php - Two Tables & Ordering By Column Not in Both -

i have 2 tables.. 1 player's session.. , 1 player's character. can't alter how tables record data.. have work these. ultimately, trying create "who online" list , need help figuring out how sort all.

account sessions (if row nowadays in list, business relationship logged in)

---------------------- | accountid | charid | ---------------------- | 1001 | 2001 | ---------------------- | 1004 | 2006 | ---------------------- | 1002 | 2003 | ----------------------

characters (shows characters active or not)

------------------------------------ | charid | accountid | charname | ------------------------------------ | 1001 | 2001 | user1 | ------------------------------------ | 1002 | 2001 | user2 | ------------------------------------ | 1003 | 2002 | user3 | ------------------------------------ | 1004 | 2002 | user4 | ------------------------------------ | 1005 | 2003 | user5 | ------------------------------------ | 1006 | 2004 | user6 | ------------------------------------

i'm trying order online followed character name. according tables.. i'd want printout this:

online user1 user3 user6

offline user2 user4 user5

what query utilize print out info when uses 2 tables , sorting sec table character names.. , whether or not they're online- 2 different sorting 2 different tables?

if there character names in session table.. it'd create whole lot easier.. don't think can alter myself. :( help?

try this

select charname, if(sessions.charid null, 'offline', 'online') status characters left bring together sessions on characters.charid=sessions.charid , characters.accountid=sessions.accountid order status desc, charname asc

this should give 2 column table charname , status, online first. fancier group_concat function too

php mysql select sql-order-by union

No comments:

Post a Comment