我怎么能过滤重复?

时间:2014-04-22 06:39:20

标签: php sql filter phpmyadmin duplicates

信息:

TABLE =赠品

FORM 1 = id

FORM 2 =用户名

FORM 3 = userid

FORM 4 =愿望

结束信息

我正在尝试通过重复的用户名和用户ID

进行过滤

注意:人们输入用户ID和用户名(用于赠品)

有人可以给我发一些代码吗?

2 个答案:

答案 0 :(得分:0)

试试这个:

SELECT  `username`,`userid` FROM `giveaway` group by `username` HAVING COUNT(`username`) > 1 UNION SELECT `username`,`userid` FROM `giveaway` group by `userid` HAVING COUNT(`userid`) > 1

答案 1 :(得分:0)

drop table test;
/
create table test
(
id number,
username varchar2(20),
userid number,
wish varchar2(40)
);
/
insert into test
values(1,'A',1,'ZXX');

/
insert into test
values(1,'A',1,'YYY');

/
insert into test
values(1,'B',2,'ZXX');
/

SELECT * FROM 
(
SELECT ID ,USERNAME,USERID,COUNT(*) OVER (PARTITION BY USERNAME,USERID) AS CNT
FROM TEST
)
WHERE CNT <2

这将为您提供唯一值