0

I have a table made up 3 columns.

user_id, certificate_type,approved

Each user_id can have multiple rows, each with a certificate_type between 1 and 30.

What I want to do is search the table with a set of different certificate types and produce a list of all the user_id's that match the combination. I only want a result if the row has approved = 1.

I can think of very complex ways to do it with multiple searches, but I suspect there is a simple query in SQL as I don't believe what I'm trying to do is hugely unusual!

juergen d
  • 201,996
  • 37
  • 293
  • 362
David L
  • 3
  • 2

1 Answers1

2

Group by the user_id and select only those having the certificate_types you define (I chose 4 random ones)

select user_id
from your_table
where certificate_type in (1,3,7,22)
and approved = 1
group by user_id
having count(certificate_type) = 4
juergen d
  • 201,996
  • 37
  • 293
  • 362