简体   繁体   中英

SELECT DISTINCT returning all values

i have problem with SQL SELECT DISTINCT , and PHP/jQuery. I'm using autocomplete function, it is working, but not as expected. I have Database with some rows:

Lukoil..
Lukoil..
Statoil..
Statoil..
Statoil..
Neste..
Neste..

And I have SQL query :

SELECT DISTINCT name FROM poi_example WHERE name LIKE '%$text%' ORDER BY name ASC

But when I typing a name in search input, I don't get distinct values:

在此处输入图片说明

So I need your offers what to do,

Database output:

INSERT INTO `poi_example` (`id`, `name`, `description`, `lat`, `lon`, `city`, `rajonas`) VALUES
(24, 'Statoil', 'Veiverių pl. 49a, Kaunas   tel.: 8-37 39 10 62   Degalinės darbo laikas Visą parą  Plovyklų darbo laikas: Visą parą', '54.88111', '23.89360', 'Kaunas', 'Aleksotas'),
(25, 'Statoil', 'Karaliaus Mindaugo pr.34a, Kaunas   tel.: 8-37 42 37 29      Degalinės darbo laikas Visą parą  Plovyklų darbo laikas: Visą parą', '54.89398', '23.91332', 'Kaunas', 'Naujamiestis'),
(26, 'Statoil', 'Tvirtovės al. 33A, Kaunas  tel.: 8-37 33 71 53      Degalinės darbo laikas Visą parą', '54.91333', '   23.92631', 'Kaunas', 'Žaliakalnis'),
(27, 'Lukoil', 'Darbo laikas: 00-24', '54.77708', '     24.11988', 'Kaunas', 'Petrašiūnai'),
(28, 'Lukoil', 'Darbo laikas: 06-22', '54.85523', '     24.44175', 'Kaišiadiorys', 'Autostrada'),
(32, 'Neste', 'Dirba visÄ… parÄ… 24/7', '55.665701', '21.175737', 'KlaipÄ—da', 'KlaipÄ—dos'),
(33, 'Neste', 'Dirba 24/7', '55.948191', '25.588700', 'Rokiškis', 'Rokiškio');

You could try to use an aggregate function.

SELECT name
FROM poi_example
WHERE name LIKE '%$text%'
GROUP BY name
ORDER BY name ASC

its obvious that the problem is on your application. No way a distinct would return duplicate values, specially because you say that the query works on your Database.

Are tou sure you are executing that exact query? Maybe if you post some code we can help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM