Welcome, Guest
  • Author Topic: 3 Table Join Frustration  (Read 2519 times)

    Rugrat

    • Server what's that
    • *
    • Posts: 48
      • View Profile
      • Email
    3 Table Join Frustration
    « on: 04/26/07, 17:18 »
    Table Products
    Product_ID  | Product_Name |

    Table Grades
    Grade_ID | Grade_Name

    Table ProductGrades
    Product_ID|Grade ID

    I need a three table SQL statement that will print out the following

    Product Name: Wahtever
    Grades: Grade 1, Kindergarten, Grade 8...etc for how many there could possible be in Table ProductGrades
    ______________________________________________________________________________________
    Product Name: Wahtever
    Grades: Grade 1, Kindergarten, Grade 8...etc for how many there could possible be in Table ProductGrades

    etc... for all products

    Can anyone help please?


    Jorge Solis

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 14616
      • View Profile
    Re: 3 Table Join Frustration
    « Reply #1 on: 04/27/07, 10:50 »
    try:

    select Product_Name,  Grade_Name from Products as p
    left join ProductGrades as PG on P.Product_ID=PG.Grade ID
    left join Grades as G on PG.Grade_ID=G.Grade_ID

    This will repeat the product name several times, just show once in your loop and iterate over the other column

    Jorge