eevan79 Posted July 26, 2010 Share Posted July 26, 2010 I tried to join same table (with aliases) but cant make to work. Here is code (separate): SELECT * FROM ".$table_prefix."online_users ORDER BY user ASC and SELECT session FROM ".$table_prefix."online_users WHERE session='".$session."' and SELECT user_name,user_id FROM ".$table_prefix."users ORDER BY user_date DESC LIMIT 1 How to do this in one single query? (is it possible?) Link to comment https://forums.phpfreaks.com/topic/208880-join-same-table/ Share on other sites More sharing options...
ldb358 Posted July 26, 2010 Share Posted July 26, 2010 SELECT * FROM ".$table_prefix."online_users WHERE session='".$session."' ORDER BY user ASC, user_date DESC LIMIT 1 should work Link to comment https://forums.phpfreaks.com/topic/208880-join-same-table/#findComment-1091080 Share on other sites More sharing options...
eevan79 Posted July 26, 2010 Author Share Posted July 26, 2010 Oh...you didnt understand . This is SELECT with different conditions (WHERE and LIMIT). In first I need to select all to get all users online. Second query check if user session exists (if not its INSERT another 'session' +1 user online). And third query checks last registered user from different table ('users' not 'user_online'). But this can be separated query. I want at least to "wrap" first 2 queries in one. --- Sorry I wrote wrong title of this topic - "Join same table". Link to comment https://forums.phpfreaks.com/topic/208880-join-same-table/#findComment-1091081 Share on other sites More sharing options...
Philip Posted July 26, 2010 Share Posted July 26, 2010 Wait, if you're wanting to return ALL the users online, you would already know if that session was there or not... Link to comment https://forums.phpfreaks.com/topic/208880-join-same-table/#findComment-1091085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.