Help Me! Multiple table select in one DB

Discussion in 'MySQL' started by b0sAnChE, Feb 7, 2009.

  1. #1
    Hi DP Members.

    I have this problem:

    I have a DB

    which contains this tables:

    1. Table "category" : "id" "title"

    2. Table "subcategory": "id" "category_id" "title"

    3. Table "softare": "id" "subcategory_id" "title" ......

    How can i make a query to the db where i get the last 10 softwares where the KATEGORY id = 3

    I hope you can understand what i mean?

    Thank you
     
    b0sAnChE, Feb 7, 2009 IP
  2. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #2
    Based on what you are telling us, you CANNOT get the LAST 10 UNLESS you EITHER specify a FIELD containing a DATE or UNLESS you specify a SORT ORDER for KATAGORY id=3.

    Furthermore you are not telling us which DB engine you are using. Without knowing that there is no way you can get the correct answer except by accident.
     
    mmerlinn, Feb 7, 2009 IP
  3. b0sAnChE

    b0sAnChE Member

    Messages:
    282
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #3
    sort order by id (software table)

    this is mysql i think 4.1 version.

    if you need any other details, let me know.
     
    b0sAnChE, Feb 7, 2009 IP
  4. w0tan

    w0tan Peon

    Messages:
    77
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #4
    
    SELECT *
    FROM software
    LEFT JOIN subsubcategory
    ON  subcategory.subcategory_id = software.subcategory_id
    LEFT JOIN category
    ON category.id = subcategory.category_id
    WHERE category.id = 3
    SORT BY id DESC
    LIMIT 0,10
    
    Code (markup):
    You'll have to run it yourself and see if there are any problems, but you get the idea.
     
    w0tan, Feb 7, 2009 IP
  5. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #5
    I think this should be:

    ORDER BY id DESC
     
    jestep, Feb 7, 2009 IP
  6. b0sAnChE

    b0sAnChE Member

    Messages:
    282
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #6
    thanks it works.
     
    b0sAnChE, Feb 7, 2009 IP