Donate SIGN UP

SQL query advice

Avatar Image
Chris100682 | 15:43 Thu 27th Jul 2006 | Technology
4 Answers
Hi,
I asked for help from you guys with an SQL query yesterday and someone replied and helped really helped me, I was given the following query

select T1.src_prod_ofr, T1. source_code, T2.cit_code
FROM table1 T1
LEFT JOIN table2 T2
ON T1.src_prod_ofr = T2.src_prod_ofr

Question: If I wanted to add another table to the query how would I go about doing this? How would I write the query?




Gravatar

Answers

1 to 4 of 4rss feed

Best Answer

No best answer has yet been selected by Chris100682. Once a best answer has been selected, it will be shown here.

For more on marking an answer as the "Best Answer", please visit our FAQ.
Add it as another JOIN. Say Table3 is the name of the 3rd table. For instance :

SELECT T1.src_prod_ofr, T1. source_code, T2.cit_code
FROM Table1 T1
LEFT JOIN Table2 T2
ON T1.src_prod_ofr = T2.src_prod_ofr
JOIN Table3 T3
ON T2.cit_code = T3.cit_code

This would only return rows where Table3's cit_code is the same as Table2's cit_code. To return all records, do another LEFT JOIN instead of the normal JOIN.
Oh, and then you can add T3.<column_name> to the SELECT clause of the statement to get info from Table3.
Question Author
Obonio your are a life saver!
No problem.

1 to 4 of 4rss feed

Do you know the answer?

SQL query advice

Answer Question >>