select only one row from multiple rows MySql -
i have orders table follows:
id | cust_id| status 1     25         1 2     25         1 3     25         0 4     26         0 5     26         1 6     26         0 7     27         1 8     27         1 9     27         1 i need 2 queries:
1. fetch 'cust_id' having @ least 1 status 0.
eg. in above table should cust_id 2 rows 25 , 26 because have @ least 1 0 in 'status' column.
2. fetch 'cust_id' having status 1.
eg. in above table should cust_id 1 row 27 because has 1's in 'status' column.
assuming status numeric
select distinct cust_id  my_table status  = 0    select disctint cust_id my_table   cust_id not in (select distinct cust_id  my_table status  = 0 ) these 2 queries ..
if need both result in same select can use union
select distinct cust_id  my_table status  = 0  union  select disctint cust_id my_table   cust_id not in (select distinct cust_id  my_table status  = 0 ) 
Comments
Post a Comment