简体   繁体   English

查询以基于MySQL中的第1列选择第2列中的重复项

[英]Query to select duplicates in column 2 based on column 1 in MySQL

Let's say I have two columns: id and date. 假设我有两列:id和date。

I want to give it an id and it'll find all the duplicates of the value date of the column id. 我想给它一个ID,它将找到列ID的起息日的所有重复项。

Example: 例:

id |date
1  |2013-09-16
2  |2013-09-16
3  |2013-09-23
4  |2013-09-23

I want to give it id 1 (without giving anything about date) and it'll give me a table of 2 columns listing the duplicates of id 1's date 我想给它id 1(不提供任何有关日期的信息),它会给我一个2列的表格,列出id 1的日期的重复项

Thanks in advance! 提前致谢!

select * from your_table
where `date` in
(
  select `date`
  from your_table
  where id = 1
)

or if you like to use a join 或者如果您想使用联接

select t.* 
from your_table t
inner join
(
  select `date`
  from your_table
  where id = 1
) x on x.date = t.date

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM