2013-09-16 47 views
1

假设我有两列:id和日期。根据MySQL中第1列在第2列中选择重复项的查询

我想给它一个ID,它会找到列ID的值日期的所有重复项。

例子:

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

我想给它的ID 1(无需提供有关日期的任何东西),它会给我2列,列出id为1的日期的副本的表

提前致谢!

回答

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

,或者如果你喜欢用加入

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

感谢一大堆! :D我在周围的JOIN文件四处游荡,但我想我看错了地方 – potasmic

+0

实际上,IN子句更容易理解。但是,再次感谢。 – potasmic

相关问题