开发者

sql select duplicate records once

开发者 https://www.devze.com 2023-04-08 00:05 出处:网络
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 on

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
0

精彩评论

暂无评论...
验证码 换一张
取 消