I have this table like
postcard_to_user_id
user_from_user_id
and records like
postcard_to_user_id | postcard_from_user_id
1 | 2
1 | 3
1 | 2
4 | 3
2 | 1
And I need to get a total count of how many "postcards" (database registers) user_id = 2 SENT to user_id = 1
In the example above user_id = 2 sent 2 postcards to user_id = 1.
And I need that list to all users who sent postcards. The example above would be
2 to 1: 2
3 to 1: 1
3 to 4: 1
1 to 2: 1
[each return "line" would have: from to and total not repetiting]
Can this be done with SQL?
Or is it necessary to select all from the table and load values into an array and do a for loop with some ifs inside?
If so, how can this be done?
Thanks for any input.