0

I'm having trouble figuring out the logic behind this query.

Suppose we have a table

post_bump(post_id,user_id)

I want to result set to be - post_id, Number of times this post Id is in the table

I am using symfony's query builder which relies on DQL but if you know how to do it in SQL then I may be able to interpret the logic and put it into DQL myself.

2 Answers2

0

In SQL, you can do this using a group by and count:

select post_id,
    count(*) as times
from post_bump
group by post_id;

I am not an expert in Symfony, but see if this helps:

Community
  • 1
  • 1
Gurwinder Singh
  • 38,557
  • 6
  • 51
  • 76
0

For example if you have the following table:

enter image description here

SELECT post_bump.post_id, Count(post_bump.post_id) AS NumberOfPost_id FROM post_bump GROUP BY post_bump.post_id;
Tom
  • 1,636
  • 2
  • 13
  • 21