在Doctrine 2中按UNION命令

时间:2013-08-06 13:22:42

标签: mysql symfony doctrine-orm sql-order-by union

我想显示最后查看的10个元素。

这是我在SQL中的查询:

SELECT compte.dateConsultation AS dateObjet, societe.nom FROM compte, societe WHERE compte.idSociete = societe.id

UNION

SELECT opportunite.dateConsultation as dateObjet, opportunite.nom
FROM opportunite

UNION

SELECT contact.dateConsultation as dateObjet, CONCAT(CONCAT(personne.nom, " "),personne.prenom)
FROM contact, personne
WHERE contact.idPersonne = personne.id

UNION

SELECT piste.dateConsultation as dateObjet, CONCAT(CONCAT(personne.nom, " "),personne.prenom)
FROM piste, personne
WHERE piste.idPersonne = personne.id

UNION

SELECT tache.dateConsultation as dateObjet, tache.objet
FROM tache

UNION

SELECT evenement.dateConsultation as dateObjet, evenement.objet
FROM evenement

ORDER BY dateObjet DESC

我知道Doctrine不支持UNION。但是我需要选择所有元素并对结果执行orderBy dateConsultation。

1 个答案:

答案 0 :(得分:0)

SELECT * FROM (Your query here -- without the order by) ORDER BY dateObjet DESC