Ayesha Soto
Ayesha Soto

Reputation: 27

group by not working SQL- very basic

i did a few searches and i saw a few people try to do some kind of nested select statement in order to fix the issue. i did not understand it.

can someone help me please:

the data is already sorted by provider name, each provider name is listed more than once based on various other columns in the table. however, when i do this, i do not get one line per provider name. instead the provider names repeat as if i am not using group by

here is the code:

create table moopnjsummary2 as

select mnj.ProviderName
from moopnj mnj
group by mnj.ProviderName

Upvotes: 0

Views: 608

Answers (4)

HLGEM
HLGEM

Reputation: 96650

select mnj.ProviderName, count(*) as Providernamecount
from moopnj mnj 
group by mnj.ProviderName 

Upvotes: 1

Peter Andersson
Peter Andersson

Reputation: 2047

This is a not a full answer to your question but if all you want is a list of provider names you should use: "Select DISTINCT mnj.ProviderName ...". That will eliminiate all duplicates.

Upvotes: 0

Andrew C
Andrew C

Reputation: 699

If all you're looking for is distinct ProviderNames, try running

SELECT DISTINCT moopnj.ProviderName FROM moopnj

Upvotes: 0

Fermis
Fermis

Reputation: 181

Do you want a list of mnj.ProviderName without repeats? What is your final goal?

You could also try SELECT DISTINCT

Upvotes: 1

Related Questions