此语句对mysql 4.0以后的版本生效.
SELECT name_first, name_last, COUNT(*) AS tally,
FROM contacts
GROUP BY name_first, name_last
HAVING tally > 1;
| How can I Find Duplicated Rows in a Table? [ID 1023312.1] | |||||
| Modified 17-AUG-2011 Type HOWTO Migrated ID 5280 Status PUBLISHED | |||||
If there are too many rows in a table to efficiently inspect the table manually, you can find them with the COUNT()
function. As an example, suppose you have a table containing the names
and telephone numbers of sales contacts. Suppose further that there
are duplicate entries for some contacts. To find duplicate rows in a
table based on a couple of columns in particular, you can enter an SQL
statement like the following:
SELECT name_first, name_last, COUNT(*) AS tally,
FROM contacts
GROUP BY name_first, name_last
HAVING tally > 1;
This statement will list one row for each contact for which there is at least one duplicate entry (having the same first and last name) and give a tally of the number of entries for the contact. See Document 1023311.1 to learn how to to easily delete the duplicate entries.
|
Products
| ||
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/11780477/viewspace-705238/ ,如需转载,请注明出处,否则将追究法律责任。