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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query criteria, find multiple records only

Status
Not open for further replies.

JanesC

Technical User
Jan 15, 2002
29
GB
I have a query which records Computer Id Numbers. I want to find out which Computer Id Numbers occur most often in the database. E.g, I'm not interested in the Id Numbers that only occur once.
How can i get the query to return only the records that the user name appears more than once?
 
Try

SELECT Computers.ComputerID, Count(Computers.ComputerID) AS ComputerCount
FROM Computers
GROUP BY Computers.ComputerID
HAVING (((Count(Computers.ComputerID))>1)); Sandy
 
Thanks

Yes that has counted the number of times that the ComputerID appears, but i want to be able to view the Description for each occurance.

When i try to bring the Description field into that query, it only returns the Descriptions which match exactly.

How can i view the ComputerID and Description, but only for records where the ComputerID has appeared more than once?

I hope this makes sense?
 
Try this.

SELECT c.* FROM Computers As c
JOIN (SELECT Computers.ComputerID
FROM Computers
GROUP BY Computers.ComputerID
HAVING Count(Computers.ComputerID)>1) As q
On c.ComputerID=q.ComputerID; Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions in the SQL Server forum. Many of the ideas apply to all forums.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top