Reputation: 7026
I'm trying to get names out of a mysql table for an autocomplete (jquery ui). There are duplicate names and I don't want to show them in the suggestions. I also need to select other columns in the same query. is this possible? I'm using this query atm but there are still duplicate "s_name" returned..
SELECT DISTINCT s_name, s_time, s_auto, s_inout FROM testtable where s_name like '%" . mysql_real_escape_string($_GET['term']) . "%'
Upvotes: 0
Views: 60
Reputation: 21553
Use GROUP BY
(man page):
SELECT s_name, s_time, s_auto, s_inout
FROM testtable where s_name like '%" . mysql_real_escape_string($_GET['term']) . "%'
GROUP BY s_name
Upvotes: 1
Reputation: 7449
DISTINCT will apply to the entire row - not just the column you stick it in front of. Could you just apply the filtering in PHP after obtaining the data from MySQL?
Upvotes: 0