Home > Database > Mysql Tutorial > body text

查询一个表内相同纪录

WBOY
Release: 2016-06-07 14:56:41
Original
1179 people have browsed it

查询一个表内相同纪录 无 select?*?from?表?where?ID?in?(select?ID?from?表?group?by?ID?having?sum(1)1) select?*?from?表?where?ID1+ID2+ID3?in(select?ID1+ID2+ID3?from?表?group?by?ID1,ID2,ID3?having?sum(1)1) --方法1:????SELECT??*FROM??zy_bho??a

查询一个表内相同纪录

select?*?from?表?where?ID?in?(select?ID?from?表?group?by?ID?having?sum(1)>1)
Copy after login
select?*?from?表?where?ID1+ID2+ID3?in(select?ID1+ID2+ID3?from?表?group?by?ID1,ID2,ID3?having?sum(1)>1)
Copy after login
--方法1:????
SELECT??*FROM??zy_bho??a??WHERE??EXISTS?
??(SELECT??1??FROM??zy_bho??WHERE??[PK]??<>??a.[PK]??AND??ZYH??=??a.ZYH)?
???
--方法2:
select??a.*??from??zy_bho??a??join??zy_bho??b?
??????on??(a.[pk]<>b.[pk]??and??a.zyh=b.zyh)?
???
--方法3:
select??*??from??zy_bbo??where??zyh??in?
(select??zyh??from??zy_bbo??group??by??zyh??having??count(zyh)>1)?
--其中pk是主键或是?unique的字段。
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template