MySQL查询无法与其他数据库一起使用

时间:2012-07-03 04:08:13

标签: mysql

我有这个查询工作正常:

SELECT c.id, c.name
FROM job j
LEFT JOIN portfolio_job_category pjc ON pjc.job_id = j.id
LEFT JOIN category c ON c.id = pjc.category_id
WHERE j.end_date >= DATE( NOW( ) ) 
AND pjc.portfolio_id =3
GROUP BY c.id
ORDER BY  `c`.`id` ASC 
LIMIT 0 , 30

但是当我在下面查询时它不起作用并返回空行:

SELECT c.id, c.name
FROM commstratjobs.job j
LEFT JOIN commstratjobs.portfolio_job_category pjc ON pjc.job_id = j.id
LEFT JOIN commstratjobs.category c ON c.id = pjc.category_id
WHERE j.end_date >= DATE( NOW( ) ) 
AND pjc.portfolio_id =3
GROUP BY c.id
ORDER BY c.name;
LIMIT 0 , 30

有原因吗?

我唯一做的就是在表格前添加数据库...

1 个答案:

答案 0 :(得分:0)

你是否尝试将数据库分开;用这个符号表:`

commstratjobsjob

所以你的查询将是这样的

SELECT c.id, c.name
FROM `commstratjobs`.`job j`
LEFT JOIN `commstratjobs`.`portfolio_job_category` pjc ON pjc.job_id = j.id
LEFT JOIN `commstratjobs`.`category` c ON c.id = pjc.category_id
WHERE j.end_date >= DATE( NOW( ) ) 
AND pjc.portfolio_id =3
GROUP BY c.id
ORDER BY c.name;
LIMIT 0 , 30