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 2005 Forums
 Transact-SQL (2005)
 basic doubt in the OR condition

Author  Topic 

Sarakumar
Posting Yak Master

108 Posts

Posted - 2009-04-15 : 21:55:38
Hai,
To clarify with u people,
i have written a query, in which i have used multiple tables, using the join condition.
i have where condition also for that query. now my quetion is ,
which one take the precedence..
join or Where condition.
b'coz in the where condition i have something like
where (id =1 and isdel = 0 ) or id=5.
assuming that all the time, the record for id =5 will be returned as it is in OR condition but it is not happening..
when i investigated the query i realised one of my inner join, eliminate this record before i apply the where condition..
is the behaviour correct..

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-04-15 : 23:19:54
You'll need to post the query as what you have described would work.

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

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

kunal.mehta
Yak Posting Veteran

83 Posts

Posted - 2009-04-16 : 03:06:57
Hi,

This is working for me

declare @table1 table (id int,price float )

insert into @table1 values(1,841.75)
insert into @table1 values(2,841.75)
insert into @table1 values(3,842)
insert into @table1 values(4,842)
insert into @table1 values(5,842)

select * from @table1 where (id=1 and price=841.75) or id = 5

Kunal
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-04-16 : 03:10:51
It depends on the Query Optimizer.
One factor is the number of records in the JOINed tables. A large number would require a hash join (which is very efficient but costly since hash values need to be built). The Optimizer may consider evaluating the WHERE first to bring down the number of records to JOIN. And then maybe the JOIN can be of type NESTED LOOP or even MERGE.

So, it depends on a number of factors.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Sarakumar
Posting Yak Master

108 Posts

Posted - 2009-04-16 : 03:14:34
ok friends thanks.
i have used the union query to do my requirement
Go to Top of Page
   

- Advertisement -