MYSQL: SELECT Method - but don't show duplicates / GROUP or DISTINCT?

拜拜、爱过 提交于 2019-12-30 08:11:58

问题


How can I select and don't show duplicates? Actually, it's showing like that: apple | apple | apples | apple

This is my code:

$search = $_GET['q'];
$query = "SELECT * FROM query WHERE searchquery LIKE '%$search%' AND searchquery <> '$search'"; 

回答1:


You already said the magic word: DISTINCT.

SELECT DISTINCT columnname
FROM query
WHERE ....

Note that it probably won't work if you use SELECT DISTINCT * because when you select * that means select all columns, including columns which have a unique constraint such as the primary key. Only select the columns you need - stay away from * in general, and especially so when using DISTINCT.



来源:https://stackoverflow.com/questions/2581718/mysql-select-method-but-dont-show-duplicates-group-or-distinct

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!