SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Europe
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select 5 active and 5 inactive

    Hi. I have a table named competitions. A conventional table.
    There is a column called 'status' which can take two values 'active' or 'inactive'.

    I want to write sql query in which I'll be able to select maximum 5 rows with active status and maximum 5 rows with inactive.
    I can do this in 2 quieries.

    I dont have a quick solution in mind to make it in 1 query. Is there a solution for that?Thx

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    assuming that your queries use ORDER BY RAND() LIMIT 5, go ahead and use two queries
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2004
    Location
    Europe
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thanx for answer r937!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •