dechamp Posted May 30, 2010 Share Posted May 30, 2010 So I have 3 tables for my images, the main table with all the images and data, a table that has broken images reported and a third table that tracks the images. I'm using the following query below to pull the image to get them to sort by the image with the most clicks. I have around 15000 images in my database but only about 20 images recorded with clicks. With the query I'm using it pulls the images the way i want it to but instead of all images it only pulls images that have clicks. TABLES --------- media id | date | linkUrl and so on.......... clickTracking imgId (this is the same as the id form media) | ip | time | so on....... brokenImgReport imgId (again the same as id from media) | other columns..... SELECT media.*, STR_TO_DATE(media.date, '%m.%d.%Y') AS date, COUNT(clickTracking.imgId) AS clickCount FROM media LEFT JOIN clickTracking ON media.Id = clickTracking.imgId WHERE brand LIKE "%" AND pref=1 AND type=1 AND media.id NOT IN (SELECT imgId FROM brokenImgReport WHERE deleted=1) GROUP BY clickTracking.imgId ORDER BY clickCount DESC LIMIT 0, 2000 So basically it takes all the details to make the thumb nail, checks brokenImgReport to make sure it's not marked as deleted and then checks clickTracking to see how many times it's been clicked. I want it to return 2000 results whether it has a click count or not..... but instead it only is returning the number of thumbs that have at least 1 click. Other than that everything else with the query works fine. Quote Link to comment https://forums.phpfreaks.com/topic/203380-pulling-all-results-from-main-table-using-left-join-from-a-another-table/ Share on other sites More sharing options...
dechamp Posted May 30, 2010 Author Share Posted May 30, 2010 I was just grouping it by the wrong column, i changed it from clickTracking.imgId to media.id and bam! it works. Quote Link to comment https://forums.phpfreaks.com/topic/203380-pulling-all-results-from-main-table-using-left-join-from-a-another-table/#findComment-1065458 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.