Skip to content
Advertisement

How to check if all instances of a DB row are the same and if so count + 1 in SQL?

I have the following SQLite DB table:

I need to be able to run a query to find out out of these apps, which ones have NO active vendors.

In the above example, app 255 and app 675 have no active vendors (0), therefore the return of my query should be 2.

So far, I am only able to run a query to get the number of rows that are ‘false’, but not the number of apps which are false in ALL instances:

SELECT COUNT(*) FROM app_vendor WHERE active = 0

summing up: if all rows of a single app are ‘false’, that should add 1 to the count.

Advertisement

Answer

This query will give you a list of apps with NO active vendors:

To count the records you could wrap it in a subquery:

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