Harris Vrachimis
Harris Vrachimis

Reputation: 1

How to count the number of records in an sql database

I am using the below query to get distinct records from 4 specific columns in an sql DB.

SELECT DISTINCT customer,
       product,
       category,
       sector
FROM data_table

I need to add the count of products in this query. Any ideas?

Upvotes: 0

Views: 42

Answers (1)

Zaynul Abadin Tuhin
Zaynul Abadin Tuhin

Reputation: 32011

are you find something below

select count(*) from
(SELECT DISTINCT customer, product, category, sector 
FROM data_table
) a

or do you need window function count() if your dbms support

SELECT DISTINCT customer, product, category, sector,
count(*) over()  as cnt
FROM data_table

Upvotes: 2

Related Questions