views:

55

answers:

5

I have a typical situation. my table has four column. (id, user, col2, status)

I want to write a query which gives me the results of col2. But it has a column status which has (0/1). So I want only col2 data which has 0 status + a user's all data (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

My result should be like. I want sam's all result + other's only 0 status result.

id user col2 status

    1  sam   aa   1
    2  sam   bb   0
    3  sam   cc   1
    4  max   dd   0
    7  jam    ff  0
+1  A: 
select * from the_table where user = 'sam' or status = 0 order by id
Thilo
+1  A: 
select *
from yourtable as t
where t.user = "sam"
   or t.status = 0
Björn
+2  A: 

How about

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

?

Simon
+1  A: 
SELECT *
FROM YOUR_TABLE
WHERE user = 'sam' OR
      status = 0

We use OR in the WHERE clause so that it will be true for all of sam's rows and for all other rows which have status as 0

codaddict
+1  A: 

your where condition would be: where (user = 'sam' or status = 0)

JohnoBoy