0

easy question i think.

I have this table

+-----------------------------+
+ ip | campaignid             +
+-----------------------------+
+  1.1.1.1 | 3                +
+  1.1.1.1 | 17               +
+  1.1.1.1 | 4                +                 
+  2.2.2.2 | 8                +
+-----------------------------+

i want to get a query where ip = '1.1.1.1' like this:

+-----------------------------+
+ ip       | count | campaigns+
+-----------------------------+
+  1.1.1.1 |     3 | 3,17,4   +
+-----------------------------+

I know how to get this done in php, but is it possible to get this result with an sql query?

Thank you very much in advance.

Lucas
  • 159
  • 13

1 Answers1

4
SELECT
   ip
 , COUNT(ip) AS count
 , GROUP_CONCAT(compaignid) AS campaigns
FROM table_name
GROUP BY ip
Jared Farrish
  • 48,585
  • 17
  • 95
  • 104