ooo-Ghost-ooo ooo-Ghost-ooo - 3 days ago 6
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

Try this query:

 SELECT respond_id, incident_id, pnt_id FROM TBL 
 WHERE pnt_id IS NOT NULL
 UNION
 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

Comments