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
By MySQL version 10.5 I assume you mean MariaDB version 10.5... seeing as MySQL is only on version 8.0 at the moment ;)
I'm not too familiar with the syntax differences between MySQL and MariaDB, but here's a query that works in MySQL 8.0... which technically should work for you in MariaDB 10.5 (seeing as they've had window functions since 10.2 - https://mariadb.com/kb/en/window-functions-overview/)
Hope this helps :)