mysql - How to retrieve all records based on condition -


database records

i have table below each n_id(i.e 43, 54, 32, 46 , 24) has 3 records. due reason, n_id "21 , 39" has 1 record.

requirement: query records excluding c_type ! = 2 , status should 1.

query used:

select a.n_id, a.c_type, a.c_file_type, a.status  table  a.config_type != 2        , a.status = 1        , exists (select 1                    table b                    a.n_id = b.n_id group b.n_id, b.c_type, b.status                    having count(b.status) > 1                   ) 

output: i'm getting records expected excluding c_type = 2.

now question how change existing query additional records n_id='21, 39'? since records not retrieved part of query.

table data got above query except record n_id = 21, 39, not retrieved. want highlighted records well.

new table

what happens if remove "having count(b.status) > 1" in exists query? filter out records that, when grouped according group by, result in null status. don't think because group this.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -