Link to home
Start Free TrialLog in
Avatar of techques
techques

asked on

How to write SQL with and or

Hi

I have a query need to select the result with
transactiontypeid = 1,2,3,4 and status=0 and alltranid=0

But, the following query select status=1 and alltranid=1

How should i solve it?

select [id]=t.id, [alltranid], [transactiontypeid], [type]=r.type, [clientid]=t.clientid, [nickname]=c.nickname, [currency]=t.currency, [ucurrency]=u.currency,[status]
from alltransaction t inner join client c on t.clientid = c.id 
inner join currency u on t.currency = u.currency 
inner join transactiontype r on t.transactiontypeid = r.id 
where alltranid = 0 and status=0 and transactiontypeid=1 or transactiontypeid=2 
or transactiontypeid=3 or transactiontypeid=4
order by [id] desc

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RiteshShah
RiteshShah
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
this may work as well.



select [id]=t.id, [alltranid], [transactiontypeid], [type]=r.type, [clientid]=t.clientid, [nickname]=c.nickname, [currency]=t.currency, [ucurrency]=u.currency,[status]
from alltransaction t inner join client c on t.clientid = c.id 
inner join currency u on t.currency = u.currency 
inner join transactiontype r on t.transactiontypeid = r.id 
where alltranid = 0 and status=0 and (transactiontypeid=1 or transactiontypeid=2 
or transactiontypeid=3 or transactiontypeid=4)
order by [id] desc

Open in new window