r34627673
r34627673

Reputation: 323

How to use SQL Distinct Properly?

I have table like this:

table supervisor

enter image description here

I want the result like this:

enter image description here

and like this

enter image description here

I use this query, but this doesn't work out

Select Lecturer1,
Count(Student)
From supervisor

I use this also

Select Distinct Lecturer1,
(Select Count(Student) From Supervisor)
From Supervisor
Order By Supervisor.Lecuter1

still doesn't work out.

Upvotes: 0

Views: 65

Answers (1)

luly
luly

Reputation: 614

When using an aggregate property such as Count(), Min(), Max(), Sum() etc.. You will have to 'Group By' any other column you are trying to query.

Such as

  Select Lecturer1,Count(Student)
    From supervisor
  Group by Lecturer1

Distinct will give you the distinct from each column selected in totality.

Upvotes: 2

Related Questions