mysql帮助...麻烦返回数据

时间:2011-06-22 17:17:26

标签: mysql

在我的网站上,我有一种方法允许登录用户将文章标记为收藏,当登录文章时突出显示为保存为收藏夹,但如果用户没有收藏夹,我无法获得查询返回任何数据,我的查询有什么问题?

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

4 个答案:

答案 0 :(得分:3)

LEFT JOIN

使用JOIN而不是favourite_employers

答案 1 :(得分:2)

我知道这可能看起来很愚蠢,但您是否使用;结束了查询?

答案 2 :(得分:2)

最好看到数据库架构,但LEFT JOIN可能需要favourite_employers

答案 3 :(得分:0)

原因可能是因为这次加入:

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

没有返回,因为没有收藏夹