If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > SQL Join Query Syntax

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-26-08, 06:55
ozzii ozzii is offline
Registered User
 
Join Date: Mar 2007
Posts: 194
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.
Reply With Quote
  #2 (permalink)  
Old 05-26-08, 07:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
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'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On