1

To provide more info to my question, modify the inserted image.

https://i.stack.imgur.com/1IuID.jpg

SELECT pro.id
     , pro.featured
     , pro.price_per_night
     , pro.meta_title
     , img.image
  FROM properties AS pro
  INNER JOIN images AS img 
    ON pro.id = img.imageable_id
 WHERE pro.featured = 1

With this query, all images that meet the query are displayed. That is, images are displayed: image4, image5, image6, image7, image8, and image9.

If I order LIMIT = 1, for example, only one image is displayed, more precisely the "image4". No more images are displayed.

I would like to change the query to display the first image of the fields that match the query. More precisely, I must show "image4" and "image7".

Thanks again for your help

2 Answers2

1

mysql limit

SELECT pro.id, pro.featured, pro.price_per_night, pro.meta_title, img.image
FROM properties AS pro 
INNER JOIN images AS img ON pro.id = img.imageable_id 
WHERE pro.featured = 1
LIMIT 1
James Z
  • 12,209
  • 10
  • 24
  • 44
feiiiiii
  • 1,480
  • 1
  • 12
  • 27
0

You need to have a id to image and to get first image use image_ID.

SELECT pro.id
 , pro.featured
 , pro.price_per_night
 , pro.meta_title
 , img.image

FROM properties AS pro

JOIN images AS img

ON pro.id = img.imageable_id

WHERE image_id=1

betrice mpalanzi
  • 1,436
  • 12
  • 16