Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2007
    Posts
    212

    Unanswered: SQL Join Query Syntax

    Hi,

    I have a database with the following tables:

    tbl_joblistings
    listing_ID - Primary key
    job_title
    job_desc

    tbl_job_languages
    listing_ID
    language_ID

    tbl_languages
    language_ID - Primary key
    language_Name - Unique

    tbl_job_industries
    listing_ID
    industry_ID

    tbl_industries
    industry_ID - Primary key
    industry_Name - Unique


    tbl_joblistings and tbl_languages has a 1 to many relationship with tbl_job_languages and table tbl_joblistings and tbl_industries has a 1 to many relationship with tbl_job_industries. Both tbl_job_languages and tbl_job_industries is made up of a compound primary key.

    what is the sql syntax to join these tables if I want to search a job by language_Name and industry_Name. E.g. select everything from tbl_joblistings where language_name is French and industry sector is IT?

    Any help will be much appreciated. Cheers.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Code:
    SELECT tbl_joblistings.listing_ID
         , tbl_joblistings.job_title 
         , tbl_joblistings.job_desc  
      FROM tbl_joblistings 
    INNER
      JOIN tbl_job_languages
        ON tbl_job_languages.listing_ID = tbl_joblistings.listing_ID
    INNER
      JOIN tbl_languages
        ON tbl_languages.language_ID = tbl_job_languages.language_ID
       AND tbl_languages.language_Name = 'French'
    INNER
      JOIN tbl_job_industries
        ON tbl_job_industries.listing_ID = tbl_joblistings.listing_ID
    INNER
      JOIN tbl_industries
        ON tbl_industries.industry_ID = tbl_job_industries.industry_ID
       AND tbl_industries.industry_Name = 'IT'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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