SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I build this SQL Query?

    Anyone know how I can get the maximum ID for the first two records from a table where the categoryID = "SomeValue"?

    In the example below if the categoryID = 5 then the maximum ID is 4 as I just want the first two records. How would I do this in SQL using MySQL?


    //Example ( I just put the dots in to make it clearer )

    ID....CategoryID.......Product_Name
    3..............5.....................Fridge
    4..............5....................Cooker
    7..............5.............Microwave Oven
    8..............5....................Freezer
    9..............8.................DVD Player
    10............8..................Computer


    Cheers for any advice,

    CaptainChainsaw

  2. #2
    SitePoint Addict seanmayhew's Avatar
    Join Date
    Aug 2002
    Posts
    209
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Select * from table where CategoryID = $catID Limit 2;?

  3. #3
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM [table] WHERE CategoryId = $catId ORDER BY ID DESC LIMIT 2;
    John

  4. #4
    SitePoint Member
    Join Date
    Aug 2002
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, I've got my problem sorted out now.

    Your replies are much appreciated!


    Cheers,

    CaptainChainsaw


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
  •