Snippets v2

Languages
My Snippets

Counting records across tables Login or Register to Bookmark this snippet

Description SQL

The example in this query counts the number of events associated with each calendar.

It returns the calendar table's rows, along with a count of event table's rows associated with it.

The Code Download
  1. SELECT
  2.     c.*,
  3.     COUNT(e.id) AS cnt
  4. FROM
  5.     calendar c,
  6.     events e
  7. WHERE
  8.     e.calendar_id=c.calendar_id
  9. GROUP BY
  10.     c.calendar_id
Credits Contact JC

Added by JC on 14th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment