You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
id NOT IN ( SELECT id FROM ( SELECTmin( id ) AS id FROM Person GROUP BY email ) AS m );
376
+
id NOT IN (
377
+
SELECT id
378
+
FROM (
379
+
SELECTmin( id ) AS id
380
+
FROM Person
381
+
GROUP BY email
382
+
) AS m
383
+
);
377
384
```
378
385
379
386
应该注意的是上述解法额外嵌套了一个 SELECT 语句,如果不这么做,会出现错误:You can't specify target table 'Person' for update in FROM clause。以下演示了这种错误解法。
@@ -383,7 +390,11 @@ DELETE
383
390
FROM
384
391
Person
385
392
WHERE
386
-
id NOT IN ( SELECTmin( id ) AS id FROM Person GROUP BY email );
393
+
id NOT IN (
394
+
SELECTmin( id ) AS id
395
+
FROM Person
396
+
GROUP BY email
397
+
);
387
398
```
388
399
389
400
参考:[pMySQL Error 1093 - Can't specify target table for update in FROM clause](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause)
id NOT IN ( SELECT id FROM ( SELECTmin( id ) AS id FROM Person GROUP BY email ) AS m );
376
+
id NOT IN (
377
+
SELECT id
378
+
FROM (
379
+
SELECTmin( id ) AS id
380
+
FROM Person
381
+
GROUP BY email
382
+
) AS m
383
+
);
377
384
```
378
385
379
386
应该注意的是上述解法额外嵌套了一个 SELECT 语句,如果不这么做,会出现错误:You can't specify target table 'Person' for update in FROM clause。以下演示了这种错误解法。
@@ -383,7 +390,11 @@ DELETE
383
390
FROM
384
391
Person
385
392
WHERE
386
-
id NOT IN ( SELECTmin( id ) AS id FROM Person GROUP BY email );
393
+
id NOT IN (
394
+
SELECTmin( id ) AS id
395
+
FROM Person
396
+
GROUP BY email
397
+
);
387
398
```
388
399
389
400
参考:[pMySQL Error 1093 - Can't specify target table for update in FROM clause](https://stackoverflow.com/questions/45494/mysql-error-1093-cant-specify-target-table-for-update-in-from-clause)
0 commit comments