Returning a number instead of a table?

I have this query that yields a table however it should only return a number since the intent is for the user to only select one 'database_name' (this Question sits in a Dashboard).

    SELECT "dbinstance"."kvstore_kvstore"."database_name" AS "database_name", count(*) AS "count"
FROM "dbinstance"."kvstore_kvstore"
WHERE ((lower("dbinstance"."kvstore_kvstore"."namespace") like '%metadata%')
   AND (lower("dbinstance"."kvstore_kvstore"."key") like '%dbinstance-api-client%') AND {{database_name}})
GROUP BY "dbinstance"."kvstore_kvstore"."database_name"
ORDER BY "dbinstance"."kvstore_kvstore"."database_name" ASC

How can I change the SQL so that it returns only a number, the count, essentially and not a table?

Thank you kindly,

Hi @Antoine
If you don't want to return a specific column, then don't include it in the SELECT-clause, and don't group by it either. And order doesn't make sense here.

SELECT count(*) AS "count"
FROM "dbinstance"."kvstore_kvstore"
WHERE 
  lower("namespace") like '%metadata%'
  AND lower("key") like '%dbinstance-api-client%'
  AND {{database_name}}
1 Like

Thank you as always Flamber! :slight_smile:
I'm building, partly thanks to your help btw, a dashboard where we'll be able to track feature usage per customer. I'll pipe via the API the results in Synatics and hopefully there I can store it and create event based triggers to alert the CSM's when a customer flags for something like no login in a while for example. If ever you guys use Procurify I hope I can return the favor of your excellent support somehow.

Cheers and have a good weekend!

Antoine