Skip to content
Advertisement

Select values for a column only if there are no rows with that value that satisfy a condition

I have a table that stores logs of http fetches, let’s say we have two columns: fetch_url and success. A few example rows:

As you can see, there is at least one fetch for A that succeeded, but not a single fetch succeeded for B or for C. How can I write a query that will select only those fetch urls that have never succeeded? i.e.:

I’m trying to use some combination of GROUP BY, COUNT, and HAVING, but I can’t get a correct query working.

Advertisement

Answer

You can use aggregation:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement