I have a table with categories
Categories
id | title | visible
1 | one | 1
2 | two | null
3 | three | 1
a table with photos from the categories above
Photos
id | category_id | title | visible
1 | 1 | photo.one | 1
2 | 1 | photo.two | null
3 | 1 | photo.three | 1
4 | 1 | photo.four | 1
5 | 2 | photo.five | null
6 | 2 | photo.six | 1
7 | 3 | photo.seven | 1
8 | 3 | photo.eight | 1
9 | 3 | photo.nine | 1
I need to take only 2 photos with photos.visible = 1 from every category with category.visible = 1.
I tried with limit but i can limit only all records, not per category.
The result has to be
Result
id | category_id | title | visible | category_title
1 | 1 | photo.one | 1 | one
2 | 1 | photo.three | 1 | one
3 | 3 | photo.seven | 1 | three
4 | 3 | photo.eight | 1 | three
Any help please?