locked
inner query to join three tables and display in one gridview RRS feed

  • Question

  • User-1183458339 posted

    Dear All,

    Can any one tell me how to join three tables and display in a gridview . I've three tables in mysql php

    Table 1

    order_id |  name | custProd_id

       1            tim         2

       2            Jon         1

    Table 2

      custProd_id | Prod_id | quantity

           1                2            1

            2               3             1

     Table 3

          Prod_id |  Prod_name

              2            Nike shoes

              3            Addidas shoes

    Now in asp.net, I would like to bind my gridview and display  Table 1, but instead of custProd_id , I would like to display prod_name. How do I Join these 3  tables and bind them in gridview in asp.net. Any favour is appreciated. Thank you in advance.

    Sunday, April 27, 2014 2:36 PM

All replies

  • User-1360095595 posted

    Inner join table 1 & 2 on custProd_id, and inner join table 2 & 3 on Prod_id. It's that simple. And select whatever column(s) you're interested in displaying in the grid. 

    Sunday, April 27, 2014 2:45 PM
  • User-1183458339 posted

    Hello ,

    I've tried the following query in mysql -

    SELECT Table1.order_id,

                Table1.name,

                Table2.prod_id,

                Table3.prod_name

    INNER JOIN Table1 AND Table2 ON custProd_id

    INNER JOIN Table2 and Table3 ON prod_id

    But it is throwing me an error #1064

    Sunday, April 27, 2014 3:19 PM
  • User269602965 posted
    SELECT 
      T1.order_id,
      T1.name,
      T2.prod_id,
      T3.prod_name
    FROM
      Table1 T1
    INNER JOIN Table2 T2 ON T1.custProd_id = T2.custProID 
    INNER JOIN Table3 T3 ON T2.prod_id     = T3.prod_id
    /
    
    

    Tuesday, April 29, 2014 10:58 PM