Jump to content

Join same table


eevan79

Recommended Posts

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

Oh...you didnt understand :D .

 

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

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.