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!

Querying a query?

Status
Not open for further replies.

michaelw00d

Programmer
Apr 11, 2007
2
US
Hi,
Im not sure how I am supposed to calculate the result I require without somehow querying the initial query in mySQL.

I basically have a table which has GroupID's and Matches in it. I want to run a query which shows all the records where there are more than 2 Matches, and show how many records there are per GroupID.

I would normally make a query which gets all the records where there are more than 2 matches, then make a query which sums them and groups them, as I normally work in MS Access. However I don't know how to do the same result in mySQL.

Just to clarify:
TABLE
GroupID Matches
1 2
1 3
1 4
1 1
2 4

RESULT REQUIRED
GroupID COUNT(Matches)
1 2
2 1

Thanks for any help!
 
What about this:

select GroupID, count(Matches)
from Table
where Matches > 2
group by GroupID
 
Thank you.

I spent like an hour last night trying all types of combinations and I thought that was the first! I blame it on being up late :p

Thanks for the help, Michael.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top