SQL Join Help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

SQL Join Help

Post by wizzard81 »

Hello,

I'm have 2 tables as follow my users table and my online_users table.

I want to show on my pages my online users first and under this the offline users. So i work with a LEFT JOIN to select my online users first but i don't know how i can first show my online users random. If i do order by rand() then it doesn't show the online first but the whole members table random.

I work also via a navigation with 100 users per page.

Does someone knows a working solution?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

users LEFT JOIN online_users ON ...
selects all users, if there is no matching record in online_users those fields are considered NULL and that you can use for ORDER BY.
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

but is it possible to select random from the online users and then the others users.

Only random on the online ones and under the online then the offlines(users table)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sounds like a UNION
wizzard81
Forum Commoner
Posts: 66
Joined: Wed Jan 15, 2003 6:05 am
Location: Belgium
Contact:

Post by wizzard81 »

union?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Post Reply