Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to write Join Query for 3 tables

    i have 3 tables:- sector, category, subategory

    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....

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,225
    Thanks
    23
    Thanked 606 Times in 605 Posts
    SELECT s.sector-name, c.category-name, sub.subcat-name
    FROM `sector table` s, `category table` c, `subcategory` sub
    WHERE s.id = c.secid
    AND c.secid = sub.secid


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •