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

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Basic SQL Help

Author  Topic 

Marge0512
Starting Member

6 Posts

Posted - 2011-11-17 : 15:00:24
Hello, i don't have anything fancy here. Most will be bored but I just wanted to make sure that what I have will not create problems. I have four tables that are linked by a case number. Is this SQL ok?

select Distinct * from Table1 A, Table2 B, Table3 C, Table4 D
where A.Casenum = B.Casenum
and B.Casenum = C.Casenum
and C.Casenum = D.Casenum

Order by A.Casenum

Thanks in advance!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-11-17 : 15:03:20
Have you tested it? Why aren't you using proper JOIN syntax?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-11-17 : 15:16:15
well you might if you're not ANSI

And why DISTINCT? Don't cide if you don't need it

Same with Order by

Always format your code

and Always upper case SQL commands


SELECT *
FROM Table1 A
INNER JOIN Table2 B
ON A.Casenum = B.Casenum
INNER JOIN Table3 C
ON B.Casenum = C.Casenum
INNER JOIN Table4 D
ON C.Casenum = D.Casenum
ORDER BY A.Casenum




Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

Marge0512
Starting Member

6 Posts

Posted - 2011-11-17 : 16:25:29
That's what I was wondering....if I needed the inner join or not. I did test this and it worked fine though. I will take off the distinct.

Thank you so much for the responses!!
Go to Top of Page
   

- Advertisement -