mhmd mhmd - 2 months ago 5
MySQL Question

Use And Or in one query

I want to use and or in one query in mysql.

How do i do that?

i try this query but it didn't give me the result i want

i did some search some one say put () also didn't work

select * from tbl_staff where db_user='".$_SESSION['username']."' and
db_status!='Done' and db_status!='Cancelled' or db_transfered='$name'


i try to put ( ) for the and like i read in some answer here but also didn't work
this query give me also the done and cancelled status and that what i don't want

the idea like this i have a table

username transfered status
00021 mhmd done
00022 mhmd Running
00021 Running


the output will be
the last 2 rows only that mean the user 00021 name mhmd have 1 task and the second is transferred to him from the username 00022 should also appear to 00021 without the done one

Answer

What you explained right now:-

Select * FROM tbl_staff WHERE db_status!='Done' AND db_status!='Cancelled' AND (db_user='".$_SESSION['username']."'  OR db_transfered='$name')
Comments