大家好我正在尝试获取所有记录而不重复。
这里是我的示例数据库记录。
(`id`, `productName`, `description`)
-----------------------------------------------
(1, 'OpenIDM', 'Platform for building enterprise provisioning solutions'),
(2, 'OpenAM', 'Full-featured access management'),
(3, 'OpenDJ', 'Robust LDAP server for Java'),
(4, 'OpenDJ', 'Robust LDAP server for Java') !!This line should not appear after SQL result
我想用SQL获得什么
(`id`, `productName`, `description`)
-----------------------------------------------
(1, 'OpenIDM', 'Platform for building enterprise provisioning solutions'),
(2, 'OpenAM', 'Full-featured access management'),
(3, 'OpenDJ', 'Robust LDAP server for Java'),
以下是此主题的SQL代码段。
select productName
from ForgeRock
WHERE productName in (select productName from ForgeRock group by productName having count(*)>1)
http://sqlfiddle.com/#!9/6c924/121
如何在不重复的情况下获取所有元素?谢谢你的帮助。
答案 0 :(得分:3)
一种方法是获取最小id
的数据select min(`id`),`productname`,`description` from forgerock
group by `productname`, `description`
答案 1 :(得分:2)
对id的值有特殊要求吗?
一个简单的MIN()
函数可以解决这个问题
SELECT MIN(`id`),
`productName`,
`description`
FROM ForgeRock
GROUP BY `productName`, `description`
答案 2 :(得分:2)
我认为你必须使用DISTINCT
select distinct productName,description from ForgeRock;
这是小提琴的结果:
http://sqlfiddle.com/#!9/6c924/132