Let's say there are two tables:
Table "photos" with columns:
id,
title,
path,
user_id
And table "users" with columns:
id
username
What I want to do is select let's say 30 photos from the "photos" table but with condition that there are at most 3 photos from the same user in the fetched result set. So far I have this query:
SELECT p.*, u.username FROM photos AS p
INNER JOIN users AS u ON u.id = p.user_id
ORDER BY p.id DESC LIMIT 30;
How to create a WHERE clause to achieve max. 3 rows from the same user in the fetched result set?
EDIT: I'm using MySQL 5.1.33