ooo-Ghost-ooo ooo-Ghost-ooo - 1 year ago 73
MySQL Question

SQL: Prevent data from displaying with condition

is their any way or a query to prevent data from displaying if it has same incident_id and the pnt_id is NULL using

enter image description here

in my attached image. the highlighted data must not be displayed

is it possible? if so. can anyone help me.? and Thanks in Advance

Answer Source

Try this query:

 SELECT respond_id, incident_id, pnt_id FROM TBL 
 SELECT respond_id, incident_id, pnt_id FROM TBL
 WHERE incident_id in (SELECT distinct(incident_id) 
                       FROM TBL 
                       GROUP BY incident_id 
                       HAVING count(id) = 1);

The first part of the union will get all the not null pnt_ids and the second part will get all the records that may be null but go in the result.

Union merges the two results eliminating duplicates

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download