Reputation: 85
I have the query below, and it gets the correct data, but I need to limit the results of the join so that only the first row from the photos table is included. Here's what I have:
SELECT `listings`.*, `photos`.*
FROM `listings` JOIN `photos`
ON `photos`.`listing_id` = `listings`.`id`
WHERE `listings`.`date_expires` >= '2016-08-10' AND `listings`.`visible` = '1' AND `listings`.`spotlightListing` >= '2016-08-10'
How do I limit the above so I only get the first row from the photos table? Thanks!
Upvotes: 0
Views: 58
Reputation: 3593
SELECT `listings`.*, `photos`.*
FROM `listings`
JOIN `photos` ON `photos`.`listing_id` = `listings`.`id`
WHERE `listings`.`date_expires` >= '2016-08-10' AND `listings`.`visible` = '1'
AND `listings`.`spotlightListing` >= '2016-08-10'
limit 1
I am sure you are talking about first photo of the list record.
Upvotes: 1