SQL Help needed

Discussion in 'Databases' started by wizzard, Sep 4, 2006.

  1. #1
    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?
     
    wizzard, Sep 4, 2006 IP
  2. wizzard

    wizzard Peon

    Messages:
    160
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Anyone ???
     
    wizzard, Sep 4, 2006 IP
  3. swirl1980

    swirl1980 Peon

    Messages:
    53
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    can u not just do 2 seperate queries??
     
    swirl1980, Sep 4, 2006 IP
  4. hextraordinary

    hextraordinary Well-Known Member

    Messages:
    2,171
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    105
    #4
    rand will work on the entire query result, two queries will work nicely in this case.
     
    hextraordinary, Sep 4, 2006 IP
  5. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #5
    Do your first query, appy the RAND() function to it so your records are random. Then do a Union to the next query.
     
    ccoonen, Sep 7, 2006 IP