Mysql:选择所有字段相等的行

时间:2012-08-01 19:22:36

标签: mysql database sorting duplicates unique

如何从mysql db中删除(或选择)所有唯一行?

+-----------+----------+------------+
| FirstName | LastName | BirthDate |
+-----------+----------+------------+
| Tia | Carrera | 1975-09-18 |
| Tia | Carrera | 1975-09-18 |
| Nikki | Taylor | 1972-03-04 |
| Yamila | Taylor | 1972-03-04 |
+-----------+----------+------------+

已删除或已选择的行必须是完全重复。示例输出

+-----------+----------+------------+
| FirstName | LastName | BirthDate |
+-----------+----------+------------+
| Tia | Carrera | 1975-09-18 |
| Nikki | Taylor | 1972-03-04 |
| Yamila | Taylor | 1972-03-04 |
+-----------+----------+------------+

1 个答案:

答案 0 :(得分:4)

您想使用SELECT DISTINCT查询而不是SELECT查询。

示例:

SELECT DISTINCT
    FirstName,
    LastName,
    BirthDate

FROM YourTable;

这会将所有相同的行合并为一个结果。