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!

Counting in SQL 1

Status
Not open for further replies.

Laeg

Programmer
Nov 29, 2004
95
IE
Anyone got a nice script to calculate for each value in tblStatus a count in tblFoo.

So the result in the case below would be

Status | Count
Status1 1
Status2 1
Status3 1
Status4 2


tblFoo
==========================
StatusID | Foo
1 asdf
4 yhjhfh
3 etherh
2 asfasw
4 asdfsadf

tblStatus
==========================
StatusID | Status
1 Status1
2 Status2
3 Status3
4 Status4
 
Code:
SELECT tblStatus.Status
     , COUNT(tblFoo.StatusID) AS Count
  FROM tblStatus
LEFT OUTER
  JOIN tblFoo
    ON tblFoo.StatusID = tblStatus.StatusID
GROUP
    BY tblStatus.Status

r937.com | rudy.ca
 
Thanks, that worked perfectly
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top