How to write Join Query for 3 tables (mysql) (php)

Discussion in 'Programming' started by kamal11, May 3, 2012.

  1. #1
    i have 3 tables:- sector, category, subcategory

    sector table
    id->primary key
    sector-name

    category table
    id->primary key
    secid->Foreign key to sector table
    category-name

    subcategory
    id->primary key
    secid->Foreign key to sector table
    catid->Foreign key to category table
    subcat-name

    now i want sector-name, category-name and subcat-name from 3 tables..how to join these 3 tables....
     
    kamal11, May 3, 2012 IP
  2. wd0325

    wd0325 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think you can write like this....

    select sc.name, ct.name, sct.name from sector sc, category ct, subcategory sct where sc.id=ct.secid and sc.id=sct.secid and ct.id=sct.catid";
     
    wd0325, May 3, 2012 IP
  3. honeyclarck

    honeyclarck Peon

    Messages:
    196
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am newbie in this field. so you can ask this from Google it gives you the best solution.
     
    honeyclarck, May 4, 2012 IP