Forum Moderators: open
SELECT spot.id, spot.name, spot.url, spot.lat, spot.lng, count(img.id) as photos
FROM s_spots as spot
LEFT JOIN s_image_gallery as img ON spot.id = img.spotid
WHERE polygonid=312 GROUP BY spot.id ORDER BY spot.name ASC;
SELECT spot.id, spot.name, spot.url, spot.lat, spot.lng, count(vid.id) as video
FROM s_spots as spot
LEFT JOIN s_video as vid ON spot.id = vid.spotid
WHERE polygonid=312 GROUP BY spot.id ORDER BY spot.name ASC;
SELECT *
FROM s_spots, s_video, s_image_gallery
WHERE polygonid=312
AND s_spots.id = s_image_gallery.spotid
AND s_spots.id = s_video.spotid
GROUP BY s_spots.id ORDER BY spot.name ASC;
If that's not the output you expected, try this:
SELECT *
FROM (
s_spots AS spot LEFT JOIN s_image_gallery AS img ON spot.id = img.spotid
)
LEFT JOIN s_video AS vid ON spot.id = vid.spotid
WHERE s_spots.polygonid=312
GROUP BY spot.id
ORDER BY spot.name ASC
If that still isn't right, please post back with more details. :)