rgb192
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
this query gets 0 results
I want to write a query with 'AND'
without rewriting query
ASKER
select * from orders where (company='company' and itemid=0) AND (company='company' and itemid!=0)
is
select * from orders where $condition1 AND $condition2
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
select * from orders where condition1 --- item = 0
union
select * from orders where condition2 --- item <>0
ASKER
is there a way to do with AND
so I dont have to repeat query 2x
so I dont have to repeat query 2x
select * from orders where (company='company' and itemid=0) OR (company='company' and itemid!=0)
ASKER
or doesnt work... I want both using 'and'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I agree, I have to redesign the code
select * from orders where company='company'
and
select * from orders where (company='company' and itemid=0) AND (company='company' and itemid!=0)?