查询,根据MySQL中的列1选择列2中的重复项

时间:2022-09-23 12:24:23

Let's say I have two columns: id and date.

假设我有两列:id和日期。

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!

提前谢谢!

1 个解决方案

#1


3  

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

#1


3  

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