I have a table with personid and msg colums.
personid, msg
--------------
1, 'msg1'
2, 'msg2'
2, 'msg3'
3, 'msg4'
1, 'msg2'
I want to get total msg for each personid.
I am trying this query:
select distinct personid, count(*)
FROM mytable;
I also tried this query
select distinct personid, count(msg)
FROM mytable;
But not getting actual result.
I want this result for above data:
id, count
--------
1, 2
2, 2
3, 1
You just need to use
GROUP BYinstead ofDISTINCT. So try this query:See this SQLFiddle