I know this topic has been discussed million times, but I am having a strange output. I am trying to accomplish a job where a sql query will count the number of duplicate + non-duplicate rows. Basically I have the following table:
ID
865
501
501
501
502
865
865
My query is
select id, count(*) as total from master_huts group by id
And I am getting this
ID Name
0 (some weird number)
501 3
502 1
865 2
It's pretty straight forward, but not sure where I am wrong.
Table structure
CREATE TABLE `master_huts` (
`hutids` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
Do the following:
select count(id) as ocurences, id from master_huts group by id
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments