使用UNION的SQL查询在Doctrine Symfony [英] SQL query with UNION in Doctrine Symfony

查看:283
本文介绍了使用UNION的SQL查询在Doctrine Symfony的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于在Doctrine Symfony中翻译SQL查询的问题。我想做一个这样的事情:

I have a question about the translation of a SQL query in Doctrine Symfony. I would like to do a thing like that :

SELECT m.*
FROM member m
INNER JOIN (
  SELECT id_member
  FROM friend
  WHERE id_friend=99
  UNION
  SELECT id_friend
  FROM friend
  WHERE id_member=99
) a ON m.id=a.id_member 
WHERE m.visible=1

在此示例中,我搜索用户99的所有朋友。

In this example, i search all friends of the user 99.

我的表:


会员:(id,name,visible)

朋友(id,id_member,
id_friend,active)

Member: (id, name, visible)
Friend: (id, id_member, id_friend, active)

精度:我想使用Symfony寻呼机。

Precision : I would like to use the Symfony pager.

解决方案?谢谢!

推荐答案

DION中不支持UNION,但您可以使用RAW SQL - >

UNION is not supported within DQL, but you can issue your query using RAW SQL ->

$q = Doctrine_Manager::getInstance()->getCurrentConnection();
$result = $q->execute(" -- RAW SQL HERE -- ");

这篇关于使用UNION的SQL查询在Doctrine Symfony的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆