Get a record that is only once in the SQL table

2

I honestly do not know how to get the records that are only once from a table.

for example I have the following table:

identificacion atestado
1111           a
1111           b
2222           a
2222           b
3333           a
4444           c

What I need is a query where you only get the identifications that are only once in the table and that contain the "a" report

for the example the query should only return:

identificacion atestado
3333           a

try making this query:

SELECT eh.identificacion,COUNT(*) FROM tabla
  GROUP BY eh.identificacion
  HAVING COUNT(*) = 1

but I do not know how to specify that it only shows those that contain the 'a' certificate

    
asked by Francisco Araya 22.10.2018 в 17:29
source

1 answer

5

You can add another condition in HAVING :

SELECT identificacion,COUNT(*) 
FROM tabla
GROUP BY identificacion
HAVING COUNT(*) = 1
AND MIN(atestado) = 'a'
;
    
answered by 22.10.2018 в 17:30