开发者

mysql help...trouble returning data

开发者 https://www.devze.com 2023-03-15 04:28 出处:网络
On my website, I have a method that allows a logged in user to mark articles as a favourite, when logged in the articles are highlighted as being saved as a favourite, however if the user has no favou

On my website, I have a method that allows a logged in user to mark articles as a favourite, when logged in the articles are highlighted as being saved as a favourite, however if the user has no favourites, I cannot get the query to 开发者_Go百科return any data, what is wrong with my query?

SELECT `job_id`, 
    COUNT(jobs.job_id) as jobs, 
    `employers`.`employer_id`, 
    `logo_small`, `logo_large`, 
    `company_name`, `job_tags`, 
    `favourite_employers`.`employer_id` AS employer 
FROM (`employers`) 
LEFT JOIN `jobs` ON `employers`.`employer_id` = `jobs`.`employer_id` 
JOIN `favourite_employers` ON `favourite_employers`.`employer_id` = `jobs`.`employer_id` 
WHERE `favourite_employers`.`user_id` = '2' 
GROUP BY `jobs`.`employer_id` 
ORDER BY `jobs`.`job_id` DESC


use LEFT JOIN instead of JOIN for the favourite_employers table


I know this may seem silly, but did you end the query with a ;?


It would be good to see the DB schema but you probably need a LEFT JOIN for favourite_employers.


The reason could be because this join:

JOIN `favourite_employers` ON `favourite_employers`.`employer_id` = `jobs`.`employer_id`

is returning nothing because there is no favorites

0

精彩评论

暂无评论...
验证码 换一张
取 消