sql select duplicate records once
Lets开发者_如何学Python say I have 5 rows with the same data
|id|
--
|1 |
--
|1 |
--
|1 |
--
|1 |
if I echo those results out I'm gonna get 1111 but I only want to select duplicate records one, so instead I would get 1.
is this possible?
GROUP BY id;
in your mysql statement
Although I am not sure why you have duplicate IDs in your database -- that should be remedied.
You can either SELECT DISTINCT
to remove rows in the result that have all columns the same or you can GROUP BY
the columns you want to select which is useful if you want to get a count of the rows that have duplicates.
GROUP BY id
http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html
or
SELECT DISTINCT(id) from table
精彩评论