0
ID      domain
1      yahoo.com
2      yahoo.com
3      gmail.com
4      gmail.com

Let's say I have a statement like this

SELECT ID, domain, COUNT(*) as total FROM table WHERE blah = 123 GROUP BY domain

Is it possible to get each individual ID number, but while in a COUNT? I need to count the records but I also need the individual record ID numbers as well. I am pretty sure this is impossible but ultimately I need the totals and ID's

domain       total
yahoo.com     2
gmail.com     2

but also have the ID's (1,2 for yahoo.com) and (3,4 for gmail.com)

Cesar Bielich
  • 4,754
  • 9
  • 39
  • 81

1 Answers1

2

Use GROUP_CONCAT()

SELECT GROUP_CONCAT(ID) AS IDs, domain, COUNT(*) as total 
FROM table 
WHERE blah = 123 
GROUP BY domain
Barmar
  • 741,623
  • 53
  • 500
  • 612