-1

Mysql Query

SELECT * FROM `jobc_labor` WHERE type='Workshop' AND  RO_no='4' AND (status!='Job Not Done' OR status!='Jobclose')   

Result

Also tried

SELECT * FROM `jobc_labor` WHERE type='Workshop' AND  RO_no='4' GROUP BY `RO_no` HAVING status!='Job Not Done' OR status!='Jobclose'

AND tried with <> but same result

SELECT * FROM `jobc_labor` WHERE type='Workshop' AND  RO_no='4' AND (status<>'Job Not Done' OR status<>'Jobclose') 

My question is why mysql giving my output of the rows which has status of 'job Not Done and Jobclose??? What I am doing wrong. I want to write the query which check wether all labor type with workshop has jobclose or job not done OR they are empty which means the work is in process. please help.

Nasir Hussain
  • 139
  • 1
  • 9

2 Answers2

1

Your status condition:

AND (status!='Job Not Done' OR status!='Jobclose')

is always true because when status is equal 'Job Not Done' then status is not equal to 'Jobclose' and vice-versa.

You can change it to:

AND status!='Job Not Done' 
AND status!='Jobclose'

or use NOT IN:

AND status NOT IN ('Job Not Done', 'Jobclose')
tune5ths
  • 676
  • 6
  • 18
0

Try This query:

SELECT * FROM `jobc_labor` 
WHERE type='Workshop' AND  RO_no='4' AND status not in ('Job Not Done','Jobclose');

When you put or , you need be to more careful.

Bhanuchander Udhayakumar
  • 1,581
  • 1
  • 12
  • 30