mysql - SELECT query with if statement? -
i have table following example information in php script:
custid name type date 1 roy 20150715 1 roy -c 20150715 2 bart b 20150715
in select
query want customers type = , type = b
if type = -c
want remove a
or b
query.
if need select records customers don't have type '-c' on any row first need find customers want exclude. can done following query:
select custid yourtable `type` = '-c';
now should able find other customers:
select * yourtable custid not in ( select custid yourtable `type` = '-c' );
above 1 way achieve this. can use temporary table or join
against above subquery.
Comments
Post a Comment