How can I select with exception in mySQL -


select department mytable contact null

   department    contact     ------------- ---------     cleaning      jack     admin         peter     software      james     cleaning      (null)     cleaning      jill     hardware      (null) 

in table above, how can select department contact null excluding existed contact.

the statement above return "cleaning" , "hardware".

what expected "hardware"

how can select "hardware" or possible.

tia

i think want return rows not have non-null contacts.

select     distinct department     mytable     contact null     , department not in (select department mytable contact not null) 

or, if want without in clause:

select     distinct a.[department]     mytable left outer join     mytable b         on b.[department] = a.[department]         , b.[contact] not null     a.[contact] null     , b.[contact] null 

self join using not null condition, verify join failed checking null in where clause.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -