2010-09-20 59 views
0

我有一个典型的情况。 我的表有四列。 (id, user, col2, status)我在写一个mysql查询。帮帮我

我想写一个查询给我col2的结果。但它有一个列状态(0/1)。所以我只想要col2数据有0状态+用户的所有数据(0/1)。

id user col2 status 
1 sam aa 1 
2 sam bb 0 
3 sam cc 1 
4 max dd 0 
5 max dd 1 
6 max ee 1 
7 jam ff 0 
8 jam gg 1 

我的结果应该是这样的。我想要sam的所有结果+其他的只有0的状态结果。

id user col2 status 

    1 sam aa 1 
    2 sam bb 0 
    3 sam cc 1 
    4 max dd 0 
    7 jam ff 0 

回答

2

如何

SELECT * FROM yourTable WHERE user = "sam" OR status = 0; 

1
select * from the_table where user = 'sam' or status = 0 order by id 
1
select * 
from yourtable as t 
where t.user = "sam" 
    or t.status = 0 
1
SELECT * 
FROM YOUR_TABLE 
WHERE user = 'sam' OR 
     status = 0 

我们使用ORWHERE子句中,这样它会为所有sam的行和具有所有其他行是真实的status0

2

你的WHERE条件是: 其中( user ='sam'或status = 0)