Jump to content

pulling all results from main table using left join from a another table


dechamp

Recommended Posts

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.