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 > Simple question; simple answer?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-25-03, 18:25
ujohnc00 ujohnc00 is offline
Registered User
 
Join Date: Aug 2003
Posts: 11
Question Simple question; simple answer?

Hello all.

I am really driving myself nuts over this easy problem. Imagine that I am doing a simple join on two tables:

SELECT e.firstname, j.job_name
FROM Employee e, Jobs j
WHERE e.job_id = j.job_id

The problem is that if a record in the Employee table has no job_id (a feasible case in my situation), obviously that record will not be returned. Ideally, I would want the record returned whether or not a corresponding job_id exists, possibly returning "" if the job_id doesn't exist.

I really feel like I am missing some common knowledge, so any help is great.

Cheers!
Reply With Quote
  #2 (permalink)  
Old 08-25-03, 21:48
shev shev is offline
Registered User
 
Join Date: Jul 2003
Location: Hong Kong
Posts: 56
Re: Simple question; simple answer?

Try the below:


SELECT e.firstname, j.job_name
FROM Employee e LEFT JOIN Jobs j
ON e.job_id = j.job_id
__________________
Cheers,
Shev
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