1

I want to combine into a single SQL query both the first date and the total number of dates that are returned by a certain WHERE clause.

I can do the two separately:

SELECT DateAdded FROM table WHERE id = x ORDER BY DateAdded ASC LIMIT 1

and

SELECT COUNT(*) FROM table WHERE id = x 

But how do I merge these two queries?

BioGeek
  • 21,897
  • 23
  • 83
  • 145

1 Answers1

7

how about,

SELECT MIN(DateAdded), COUNT(*) FROM table WHERE id = x

Since you don't specifiy which engine you are using, this also avoids the far from standardized LIMIT keyword.

Community
  • 1
  • 1
Jodrell
  • 34,946
  • 5
  • 87
  • 124