在 Doctrine Symfony 中使用 UNION 进行 SQL 查询 [英] SQL query with UNION in Doctrine Symfony

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

问题描述

我有一个关于在 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、姓名、可见)
朋友: (id, id_member,id_friend,活跃)

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

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

Precision : I would like to use the Symfony pager.

解决方案?谢谢!

推荐答案

在 DQL 中不支持 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 -- ");

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

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