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
 General SQL Server Forums
 New to SQL Server Programming
 Different Approaches

Author  Topic 

JeniQ
Starting Member

29 Posts

Posted - 2009-08-20 : 12:51:10
A colleague and I were both working on the same query. She wrote her query in a manner completely unlike mine. I was wondering if I could get some advice on the two approaches.

Is either better?

Both queries return the correct (same) results and take less than one second to run.

Option #1
select Publication.PublicationID
from Publication, Event_Publication
where Publication.PublicationID = Event_Publication.PublicationID
and EventID = 3427

Option #2
select p.PublicationId
from Publication p
join Event_Publication ep on p.PublicationID = ep.PublicationID
where ep.EventID = 3427


webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-20 : 12:55:56
#2 is better.
The old way to join tables using comma like done in #1 is "deprecated" and will not work in the future.
Also #2 is much better readable.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

JeniQ
Starting Member

29 Posts

Posted - 2009-08-20 : 12:59:16
I win, I win!!! :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-08-20 : 13:03:59

Congrats!


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-08-21 : 01:45:12
Also #2 is ANSI style
If you omit where clause in #1, it is cross join

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -