我有以下查询,我想将所有重复的行返回给用户,以便他们决定使用哪一行:
SELECT * FROM `table`
INNER JOIN (SELECT * FROM table GROUP BY barcode HAVING (COUNT(id) > 1)) dup
ON `table`.`column` = `dup`.`column`
此查询的每个部分似乎都会返回正确的响应,但在将2添加到一起时,如果有意义的话,我会获得重复的重复项。关于发生了什么的任何想法?
我的表格数据
+----+------------------------+---------------------+---------------------+
| id | barcode | created_at | updated_at |
+----+------------------------+---------------------+---------------------+
| 2 | 0000000002800000008741 | 2015-10-05 12:04:52 | 2015-10-05 12:04:52 |
| 3 | 0000000002800000008738 | 2015-10-05 13:15:02 | 2015-10-05 13:37:51 |
| 4 | 0000000002800000008741 | 2015-10-05 13:22:38 | 2015-10-05 13:22:38 |
| 5 | 0000000002800000008738 | 2015-10-05 13:22:38 | 2015-10-05 13:22:38 |
| 6 | 0000000002800000008738 | 2015-10-05 13:23:29 | 2015-10-05 13:23:29 |
| 7 | 0000000002800000008738 | 2015-10-05 13:24:49 | 2015-10-05 13:24:49 |
| 8 | 0000000002800000008741 | 2015-10-05 13:24:49 | 2015-10-05 13:24:49 |
| 9 | 0000000002800000008738 | 2015-10-05 13:37:51 | 2015-10-05 13:37:51 |
| 10 | 0000000002800000008741 | 2015-10-05 13:37:51 | 2015-10-05 13:37:51 |
+----+------------------------+---------------------+---------------------+
以上查询的输出
+----+------------------------+---------------------+---------------------+
| id | barcode | created_at | updated_at |
+----+------------------------+---------------------+---------------------+
| 2 | 0000000002800000008741 | 2015-10-05 12:04:52 | 2015-10-05 12:04:52 |
| 3 | 0000000002800000008738 | 2015-10-05 13:15:02 | 2015-10-05 13:37:51 |
| 4 | 0000000002800000008741 | 2015-10-05 13:22:38 | 2015-10-05 13:22:38 |
| 5 | 0000000002800000008738 | 2015-10-05 13:22:38 | 2015-10-05 13:22:38 |
| 6 | 0000000002800000008738 | 2015-10-05 13:23:29 | 2015-10-05 13:23:29 |
| 7 | 0000000002800000008738 | 2015-10-05 13:24:49 | 2015-10-05 13:24:49 |
| 8 | 0000000002800000008741 | 2015-10-05 13:24:49 | 2015-10-05 13:24:49 |
| 9 | 0000000002800000008738 | 2015-10-05 13:37:51 | 2015-10-05 13:37:51 |
| 10 | 0000000002800000008741 | 2015-10-05 13:37:51 | 2015-10-05 13:37:51 |
| 11 | 0000000002800000008738 | 2015-10-05 13:39:05 | 2015-10-05 13:39:05 |
| 12 | 0000000002800000008741 | 2015-10-05 16:16:41 | 2015-10-05 16:16:41 |
| 13 | 0000000002800000008738 | 2015-10-05 16:39:56 | 2015-10-05 16:39:56 |
| 14 | 0000000002800000008738 | 2015-10-06 10:12:32 | 2015-10-06 10:12:52 |
| 15 | 0000000002800000008741 | 2015-10-06 10:17:30 | 2015-10-06 10:17:30 |
| 16 | 0000000002800000008741 | 2015-10-05 16:50:40 | 2015-10-05 16:50:40 |
+----+------------------------+---------------------+---------------------+