Rahim Shaikh
Rahim Shaikh

Reputation: 3

Filter query with condition

I have a table like this

Assigned_job|Assignedbyuser|Approve

8999        |co-admin1     |0

8888        |co-admin2     |1

7777        |co-admin3     |0

Now if I want to get only Approve = 1
I can simply use

where Approve = 1

and I will get this result

Assigned_job|Assignedbyuser|Approve
8888        |co-admin2     |1

and if I want to get

only Approve=1 but if Assignedbyuser='co-admin1' don't check Approve =1

the end result should look something like this

Assigned_job|Assignedbyuser|Approve
8999        |co-admin1     |0
8888        |co-admin2     |1

Upvotes: 0

Views: 67

Answers (4)

philipxy
philipxy

Reputation: 15118

only Approve=1 but if Assignedbyuser='co-admin1' don't check Approve =1

That is unclear. I suspect you want:

 where Assignedbyuser='co-admin1' or Approve = 1

Read about the two kinds of SQL case expressions, which are its analogues to the if expressions of other programming languages. There are also functions involving "if" in their names and/or definitions.

Upvotes: 0

Rohit Gaikwad
Rohit Gaikwad

Reputation: 815

You can use Case statement in where.........

WHERE CASE WHEN AssignedByUser <> 'co-admin1' THEN Approve = 1
ELSE AssignedByUser = 'co-admin1' END

Upvotes: 0

Komal K.
Komal K.

Reputation: 470

SELECT * from table 
WHERE (CASE Assignedbyuser = 'co-admin1' THEN Assignedbyuser = 'co-admin1' CASE WHEN  Assignedbyuser != 'co-admin1' THEN  Approve = 1 END) 

Try This.

Upvotes: 0

Felix Pamittan
Felix Pamittan

Reputation: 31879

A combination of AND and OR conditions:

WHERE
    (AssignedByUser <> 'co-admin1' AND Approve = 1)
    OR (AssignedByUser = 'co-admin1')

Upvotes: 1

Related Questions