Skip to content
Advertisement

How to use ‘Count’, based on a particular column in SQL

I have a query and which give the count greater than 1, but what I expect is I need the result to be based on particular column(Rollno.) How to achieve it.

Table Studies

The below query gives me Count but not as expected

The query gave me the below result

But the expected result is

As you can see the expected result is having a different InternalStaff_2 name for Adam which is not considered on the present result.

May I know how to over come this?

Note: I need the results to be displayed based on Rollno but I also need the InternalStaff_2 to be included in the result.

Advertisement

Answer

Hmmm . . . If I understand correctly, you want NULL if the internal staff columns do not match. That would be:

Here is a db<>fiddle that shows that this basically works.

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