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 > Database Server Software > DB2 > SQL Select statement and LEFT OUTER JOIN and 3 tabls, please help =(

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-26-04, 11:14
JamesAvery22 JamesAvery22 is offline
Registered User
 
Join Date: Jan 2004
Posts: 70
SQL Select statement and LEFT OUTER JOIN and 3 tabls, please help =(

SQL is definitely not my strong point. I need to add a column to an existing select statement that looks like this:
--------------

SELECT A.ID, A.SCHEDSTARTDATE, A.DBID, B.NAME, ...about 12 more columns all from the A table...
FROM FirstTable A, SecondTable B
WHERE A.STATE = B.ID

-------------
I have to join that with a third table and get just one column. Im guessing this will be a LEFT OUTER JOIN as the additional column is only present on some of the corresponding A rows.

So I thought it would look like this:
---------------
SELECT A.ID, A.SCHEDSTARTDATE, A.DBID, B.NAME, ...those 12 columns all from A..., C.NAME_HOST
FROM SecondTable B,
(FirstTable A
LEFT OUTER JOIN ThirdTable C
ON A.DBID = C.DBID)
WHERE A.STATE = B.ID
---------------

That doesnt return an error but its grabbing tons of documents, way more than original so obviously its wrong. Is the "WHERE A.STATE = B.ID" just completely off?

Any help would be greatly appreciated
Reply With Quote
  #2 (permalink)  
Old 01-26-04, 11:37
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I think what you want is:

SELECT A.ID, A.SCHEDSTARTDATE, A.DBID, B.NAME, ...those 12 columns all from A..., C.NAME_HOST
FROM FirstTable A INNER JOIN ON (a.state = b.ID)
LEFT OUTER JOIN ThirdTable C
ON A.DBID = C.DBID

HTH

Andy
Reply With Quote
  #3 (permalink)  
Old 01-26-04, 13:40
JamesAvery22 JamesAvery22 is offline
Registered User
 
Join Date: Jan 2004
Posts: 70
That worked great, thank you very much for the prompt reply, now I just gotta go hound someone who actually knows the data for info on how to join the 4th table
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