potasmic
potasmic

Reputation: 1097

Query to select duplicates in column 2 based on column 1 in MySQL

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

I want to give it an id and it'll find all the duplicates of the value date of the column 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

Thanks in advance!

Upvotes: 1

Views: 57

Answers (1)

juergen d
juergen d

Reputation: 204766

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

Upvotes: 3

Related Questions