1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How can I fetch first 5 records

Discussion in 'MySQL' started by seotraining, Oct 28, 2010.

  1. #1
    How can I fetch first 5 records in mysql? I am trying to use top 5 clause but unable to get it. Please help me with it
     
    seotraining, Oct 28, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    plog, Oct 28, 2010 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Can you post your table structure? As plog put it, first 5 is very ambiguous. It could mean the most recent 5, the first 5 rows in the table, etc.
     
    jestep, Oct 28, 2010 IP
  4. viriya123

    viriya123 Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Agree with 'Plog', you have to use 'Order by' keyword.

    Example :
    Select * from users order by join_date desc limit 5
     
    viriya123, Oct 28, 2010 IP
  5. teamaguilar

    teamaguilar Peon

    Messages:
    197
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can use LIMIT keyword as said above.
     
    teamaguilar, Nov 23, 2010 IP
  6. anjalisharma

    anjalisharma Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    select * from table name Order by asc LIMIT 5
    mysql does't support top 5 keyword. It is use in sql and oracle.
     
    anjalisharma, Nov 28, 2010 IP
  7. iama_gamer

    iama_gamer Active Member

    Messages:
    404
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    60
    #7
    ORDER BY and LIMIT function can be used
     
    iama_gamer, Dec 4, 2010 IP