我有这个查询:
query 1 =
SELECT emp.employeId,emp.nom,emp.prenom,msg.note,msg.quelleDate, emp.remarques, emp.autonome, embauche.actif as embaucheActif, embauche.embId, 'M' as source
FROM employes emp
LEFT JOIN messages msg ON msg.employeId = emp.employeId
LEFT JOIN embauche ON embauche.employeId = emp.employeId
WHERE emp.actif = 1
AND msg.quelleDate BETWEEN '2013-01-01' AND '2013-01-31'
UNION
SELECT emp.employeId,emp.nom,emp.prenom,msg.note,msg.quelleDate, emp.remarques, emp.autonome, embauche.actif as embaucheActif, embauche.embId, 'A' as source
FROM employes emp
LEFT JOIN messagesautre msg ON msg.employeId = emp.employeId
LEFT JOIN embauche ON embauche.employeId = emp.employeId
WHERE emp.actif = 1
AND msg.quelleDate BETWEEN '2013-01-01' AND '2013-01-31'
ORDER BY nom,prenom,quelleDate
而这个查询
query2 = select nom,prenom from employes where actif = 1;
我正在尝试从中获取所有query2
没有出现的employeeIdquery1
我试过了
select employeId,nom,prenom from employes where actif = 1 AND employeId in ( query1 );
但当然这不起作用,因为query1
返回超过 1 列
是否可以使用 MySQL 查询来做到这一点?或者我必须编写 PHP 算法来做到这一点?