sql查询以查找不起作用的不同元素

y53ybaqx  于 2021-07-24  发布在  Java
关注(0)|答案(4)|浏览(322)

我想运行一个查询,在那里我可以得到一个字段唯一的所有字段

Select * from announcements where title = SELECT distinct title 
FROM announcements;

但它不起作用。谁能帮帮我吗。

r7knjye2

r7knjye21#

Select * 
  from announcements 
 where title in (SELECT distinct title 
FROM announcements)
7lrncoxx

7lrncoxx2#

此查询:

select title 
from announcements 
group by title 
having count(*) = 1

返回所有唯一标题。
与操作员一起使用 IN :

select * from announcements 
where title in (
  select title 
  from announcements 
  group by title 
  having count(*) = 1
)
yxyvkwin

yxyvkwin3#

试着用圆括号
类似:从标题所在的公告中选择*(从公告中选择不同的标题);

xbp102n0

xbp102n04#

谢谢大家。我得到了我想要的东西

SELECT MIN( id ) AS id, title, issue_date, expirty_date, is_active FROM announcements GROUP BY title ORDER BY issue_date DESC

相关问题