Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
重复的MySQL行_Mysql_Sql - Fatal编程技术网

重复的MySQL行

重复的MySQL行,mysql,sql,Mysql,Sql,我想编写一个查询来挑选具有相同cottageid、from和to值的行,因此在本例中,它将挑选具有id 991和992的行。表名为datesBooked 您可以将表本身连接起来: select d1.id,d2.id from datesBooked d1 inner join datesBooked d2 on d1.cottageid=d2.cottageid and d1.from = d2.from and d1.to = d2.to

我想编写一个查询来挑选具有相同cottageid、from和to值的行,因此在本例中,它将挑选具有id 991和992的行。表名为datesBooked


您可以将表本身连接起来:

select d1.id,d2.id from datesBooked d1
   inner join datesBooked d2 on 
      d1.cottageid=d2.cottageid
      and d1.from = d2.from
      and d1.to = d2.to
      and d1.id<d2.id
从datesBooked d1中选择d1.id、d2.id
已预订d2上的内部联接日期
d1.cottageid=d2.cottageid
d1.from=d2.from
d1.to=d2.to

和d1.id您可以将表与其自身连接起来:

select d1.id,d2.id from datesBooked d1
   inner join datesBooked d2 on 
      d1.cottageid=d2.cottageid
      and d1.from = d2.from
      and d1.to = d2.to
      and d1.id<d2.id
从datesBooked d1中选择d1.id、d2.id
已预订d2上的内部联接日期
d1.cottageid=d2.cottageid
d1.from=d2.from
d1.to=d2.to
和d1.id试试这个:

SELECT * FROM datesBooked
GROUP BY cottageid, from, to
HAVING COUNT(cottageid) > 1
试试这个:

SELECT * FROM datesBooked
GROUP BY cottageid, from, to
HAVING COUNT(cottageid) > 1

哦,我忘了添加,我在这个表中有一千多个条目,cottageid 6不止两个条目,cottageid 6也不是唯一一个有多个条目的条目。哦,我忘了添加,我在这个表中有一千多个条目,cottageid 6不止两个条目,cottageid6也不是唯一一个有多个条目的。很抱歉,这只给了我22k个结果。谢谢您的尝试。:)抱歉,这只给了我2200个结果。谢谢您的尝试。:)