两个查询,查询的是同一个表,返回结果集相同,除了union还有什么办法合并结果集?

select t.*
from talk t
where t.user_id = 2
Union
select t.*
from talk t, user_contact c
where c.user_id = 2 and c.contact_type = 1 and c.be_user_id = t.user_id

不想使用 Union 也不想去重,有没有最简单的写法?

hibernate不支持Union

可不可以使用内连接和左连接 实现呢?

阅读 2.5k
2 个回答

1.union
2.使用异步发送两个sql过去再合并,效果和union一样

试一试?

select t.* from t left join user_contact c 
on t.user_id=c.be_user_id and c.user_id=2 and c.contact_type=1
where t.user_id=2 or c.user_id=2
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题