Page 1 of 1

SQL Join Help

Posted: Mon Sep 04, 2006 8:42 am
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?

Posted: Mon Sep 04, 2006 9:25 am
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.

Posted: Mon Sep 04, 2006 9:29 am
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)

Posted: Mon Sep 04, 2006 9:40 am
by feyd
Sounds like a UNION

Posted: Mon Sep 04, 2006 10:38 am
by wizzard81
union?

Posted: Mon Sep 04, 2006 10:46 am
by feyd