Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

want a query using AND

select * from orders where (company='company' and itemid=0) AND (company='company' and itemid!=0)

this query gets 0 results

I want to write a query with 'AND'
without rewriting query
Avatar of sventhan
sventhan
Flag of United States of America image

what is the difference between
select * from orders where company='company'
and
select * from orders where (company='company' and itemid=0) AND (company='company' and itemid!=0)?
Avatar of rgb192

ASKER

select * from orders where (company='company' and itemid=0) AND (company='company' and itemid!=0)

is

select * from orders where $condition1 AND $condition2


try like this

select * from orders where condition1 --- item = 0
union
select * from orders where condition2 --- item <>0
Avatar of rgb192

ASKER

is there a way to do with AND

so I dont have to repeat query 2x
select * from orders where (company='company' and itemid=0) OR (company='company' and itemid!=0)
Avatar of rgb192

ASKER

or doesnt work... I want both using 'and'
ASKER CERTIFIED SOLUTION
Avatar of sventhan
sventhan
Flag of United States of America 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
Avatar of Ephraim Wangoya

This is what you are describing

select *
from orders
where (company='company')
and ((itemid=0) OR (itemid!=0))

which negates the whole thing, this simply becomes
select *
from orders
where (company='company')

SOLUTION
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
SOLUTION
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
SOLUTION
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
Avatar of rgb192

ASKER

I agree, I have to redesign the code