#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    63
    Rep Power
    10

    multi level joint query


    Dear All

    I am sorry my english is no good, i have already tried to search about this question but still no good result.

    I have 3 tables and want to mak a view ( query with join ).
    transakTB :
    transak_id, suplier_id,

    suplierTB:
    suplier_id, supplier_Name, product_id

    productTB :
    product_id, product_name

    i want to make a joint query which is consist of :
    transak_id, suplier_name, product_name

    how can i do it with join query?

    Thanks for any kind help
    Best Regards
    Mchoud
    Last edited by mchoud; November 12th, 2017 at 09:24 AM.
  2. #2
  3. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,453
    Rep Power
    9645
    Pick a table to start with. It doesn't really matter which for this but most people choose the most "important" table, and its probably the table with the first column of results.
    For example, if you are trying to list suppliers and products for transactions then you might start with the transactions table.
    sql Code:
    SELECT transak_id
    FROM transakTB


    Then JOIN the next table that is related to transakTB. That would be suplierTB. They are related by the suplier_id columns.
    sql Code:
    SELECT
    	transakTB.transak_id,
    	suplierTB.suplier_name
    FROM transakTB
    JOIN suplierTB USING (suplier_id)

    You don't need to write "transakTB." and "suplierTB." for the columns because the names transak_id and suplier_name are unique, but I do it anyways. USING allows you to pair two columns in two tables when they have the same column name.

    Finally is the third table, productTB. It is related to the suplierTB table through the product_id.
    sql Code:
    SELECT
    	transakTB.transak_id,
    	suplierTB.suplier_name,
    	productTB.product_name
    FROM transakTB
    JOIN suplierTB USING (suplier_id)
    JOIN productTB USING (product_id)
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    63
    Rep Power
    10
    Dear my brother.
    Many thanks for the reply this is what i looking for.

    Best Regards
    Mchoud

IMN logo majestic logo threadwatch logo seochat tools logo