I have two tables, in one table is news in another is images linked with id from news
news
| id | title | main_image | services |
|---|---|---|---|
| 1 | New title | path_to_image_main_image | Photo |
| 2 | New title 2 | path_to_image_main_image | Photo |
images
| id | file_name | new_id |
|---|---|---|
| 1 | IMG_8045.jpg | 1 |
| 2 | IMG_8046.jpg | 1 |
| 3 | IMG_8047.jpg | 2 |
| 4 | IMG_8048.jpg | 2 |
| 5 | IMG_8049.jpg | 2 |
new_id is id from news table
My SQL query is
SELECT n.id, n.title, n.main_image, n.services, i.file_name FROM news AS n INNER JOIN images AS i ON n.id = i.new_id
I need to limit this query with 2 images from images table per id from news table