I need to make a list of all the items in the table feed
and show only the first 2 users who subscribe to the content, but I can not put together a query that does the list only 2 users limit 2
.
I've tried N querys and subquery, but could not get the expected result. The nearest was using group_concat
, but if it concatenates all users and does not allow limited only to two initial, and would have to usesubstring_index
for this purpose.
Query
select
feed.id
, feed.type
, user.name
from feed
inner join user on user.id = feed.user
group by feed.type
Result
Array(
[0] => Array(
[id] => 1
[type] => Comedy
[name] => Mike
)
[1] => Array(
[id] => 3
[type] => War
[name] => John
)
[2] => Array(
[id] => 6
[type] => Terror
[name] => Sophia
)
)
Expected
Array(
[0] => Array(
[id] => 1
[type] => Comedy
[name] => Mike, Papa
)
[1] => Array(
[id] => 3
[type] => War
[name] => John, Alex
)
[2] => Array(
[id] => 6
[type] => Terror
[name] => Sophia, Jessica
)
)