Limiting Per Each Group in MySQL
Not sure what this type of query is actually called. The basic idea is you have multiple tables linked together, but you want to only grab n rows from Table C per iteration of each row in Table A.
A more illustrative explanation: Suppose you have a table listing 10 albums and a table listing 100 records. You only want 5 records per each album.
As you might expect, Googling such a solution was pretty hard. A common solution was:
...[More]
A more illustrative explanation: Suppose you have a table listing 10 albums and a table listing 100 records. You only want 5 records per each album.
As you might expect, Googling such a solution was pretty hard. A common solution was:
Code:
SELECT r.* FROM albums as a
LEFT JOIN (
SELECT * FROM records LIMIT 5) r ON r.album_id=a.album_id
1132 unique view(s)