Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

question about "group by" sql select statement

Status
Not open for further replies.

windskystar73

Programmer
Jul 8, 2004
5
US
I have a table, called "person" that has "name" and "id" column that has the following data.

id, name
1 Tom
2 David
1 Tom
3 John
2 David

I want to display duplicated rows. i tried like this.
select * from person having count(*) > 1;
but it displays only one row.
but this statement returns what I want.
select * from person group by id, name having count(*) > 1;

can anybody tell me the difference between these two select statements?

thanks..
 
When using having without a group by you will get one group consisting of the complete table (as there is no where clause).

Try the query

Code:
select count(*) from person having count(*) > 1

which should give the result 5.

Code:
select * from person having count(*) > 1

should give an error.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top