You need to select data at once from the two tables item_images and item_main, and item_images should have a limit of 1. I make it like this, but displays nothing

//тут выборка из главной таблицы item_main, далее склейка JOIN (SELECT id_item AS id_item2 FROM item_images ORDER BY ASC limit 1) item_images2 ON item_main.id_item = item_images2.id_item2 

Update

 INNER JOIN item_images ON item_main.id_item = item_images.id_item 

It works, but there’s no way to push the limit.

  • Maybe there is no intersection (after all, you take just one line from the subquery)? Throw an example on sqlfiddle. - zb '
  • He uploaded the question - Rammsteinik
  • that's how it works select * from generator_16 JOIN (SELECT n as n1 from generator_16 limit 1) g16_1 on generator_16.n = g16_1.n1 \ G ******************** ******** 1. row *************************** n: 0 n1: 0 1 row in set (0.00 sec) - zb '

1 answer 1

As I understand it, for each item you need to display one image. In this case, you can use the LEFT JOIN connection, which matches one or zero records from item_images each record from item_images

 SELECT it.*, im.* FROM item_main AS it LEFT JOIN item_images AS im ON it.id_item = im.id_item