Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie Question re: Where Clause

Status
Not open for further replies.

xweyer

MIS
Sep 7, 2000
140
US
What is the difference between the following two statements

"where t1.site_id = t2.site_id"

and

"where t1.site_id* = t2.site_id"

In other words what does the asterisk signify?

 
The asterik is actually next to the equal sign with no space between them. That is the 'old' form of joins and I believe indicates a LEFT JOIN (asterick to the left of the equal). I also believe that Oracle still uses that form, but SQL Server is going away from it and eventually may not support it.

-SQLBill

Posting advice: FAQ481-4875
 
Actually TSQL 2005 does not support the '*' operator anymore.

- Paul
10qkyfp.gif

- If at first you don't succeed, find out if the loser gets anything.
 
But... to do this the right way, you need to put that condition in to the join statement, like this...

Code:
Select Field1, Field2
From   T1
       Left Join T2
         On T1.Site_id = T2.Site_Id

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
In Katmai (the next version of SQl Server) you can also use MAYBE EXISTS

Code:
Select Field1, Field2
From   T1
       WHERE MAYBE EXISTS (select * from  T2
         where T1.Site_id = T2.Site_Id);

That is basically a LEFT JOIN by using EXISTS

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
Google Interview Questions





 
You can set the compatiblity leve in 2005 to accept the old syntax.. but this is NOT reccomended...

Just learn the new syntax.. it's no big deal to figure out.
 
That left join syntax does not work properly even in 2000. Sometimes it interprets it as a left join and sometimes as a cross join. Do not under any circumstances use this syntax or you will get bad results.

Questions about posting. See faq183-874
 
Thanks to all for your detailed information. The code I'm trying to interpret was written some years ago which likely explains the outdated syntax.
 
Yes, but you need to go through your system and find all those outdated syntax examples and update them as they truly do not give the correct result set all the time.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top