0

I am relatively new programmer. I am trying to create a left join with count of unique rows in a specific column. with normal count it is working fine, nut with unique it is failing.

count(case when x.priorities = 112 then 1 end) as Urgent.

it is pulling all the records. I need to convert it into unique records.

i am looking for a direction or syntax which i can try.

James Z
  • 12,209
  • 10
  • 24
  • 44
SANAL RAJ
  • 19
  • 1

1 Answers1

0

Try using "COUNT(DISTINCT..)" clause instead of "COUNT".

Here is a simple example to do this(if we have a table named "students" with a column "department" and we want to count the number of unique departments represented in the table):

SELECT COUNT(DISTINCT department) AS unique_departments FROM students;

For your requirement try this:

COUNT(DISTINCT CASE WHEN t2.any_column = 112 THEN t2.any_column END) AS unique_values

Replace column names as per your need.

Huzaifa
  • 484
  • 4
  • 8