Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help formatting my SQL..
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

5 Posts

Posted - 11/29/2013 :  10:06:21  Show Profile  Reply with Quote
Hi everyone,

I know what I need to get for my SQL but with this, I am not returning many results. It touches 4 tables and a bit beyond me, yet I need to get it done. Here is my current SQL.

t1.QUOTE as Quote,
t3.NUM as C_NUM,
from table1 t1, table2 t2, table3 t3 , table t4
t1.randField='GOOD' and
t1.field2 = 'Y' and
t1.CREATED>=to_date('2013-01-01', 'YYYY-MM-DD') and
(t1.FLG is null or t1.FLG='N') and

t1.ID=t2.ROW_ID and
t2.FK_ID1=t3.ROW_ID and


Order by t1.CREATED;

Basically, I have 4 tables (t1,t2,t3,t4) I want to display values from each based on the other tables. I want to display (Quote, field1, field2, date2, date2) from table 1.

However I need to go to table 2, to get a value and then to table 3 to find the value, then to table 4 as well..

Can anyone clear this up for me?

Starting Member

8 Posts

Posted - 11/30/2013 :  01:04:07  Show Profile  Reply with Quote
SELECT T1.Col1, T2.Col1, T3.Col1 (any Column from t1,T2,T3,T4) FROM
BaseTable T1
JOIN 1stTable T2 ON T1.MappingClumn1 == T2.MappingColumn1 AND T1.MappingClumn2 == T2.MappingColumn2 (Can Add n number cond between T1 & T2)
JOIN 2ndTable T3 ON T1.MappingClumn1 == T3.MappingColumn1 AND T2.MappingClumn2 == T3.MappingColumn2 (Can Add n number cond between T1 & T2 & T3 (T3 must in conditions))
JOIN 2ndTable T4 ON T1.MappingClumn1 == T4.MappingColumn1 AND T2.MappingClumn2 == T4.MappingColumn2 (Can Add n number cond between T1 & T2 & T3 & T4 (T4 must in conditions))
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 11/30/2013 :  01:54:39  Show Profile  Reply with Quote
First question is whether there's a one - to - one relationship between all tables. Are they any cases where one of table may not have matches. If thats true, then you need to use OUTER JOIN (LEFT/RIGHT/FULL depending on your requirement) rather than INNER JOIN to get this working


SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000