Query mySQL show a result of several that are duplicated

0

Good morning,

I just autocomplete an input via mySQL

the problem is that if I have in a table clients, the names

camilo Camilo Carlos

by pressing "c" in the input the three results appear, that is to say, the two camilos usually take me

as I could do so that only the options appear

camilo Carlos

ie ignore that there are two "camilo" and show me only 1, I put LIMIT 1 but I learned that it shows only one in this case camilo since it is sorted in ascending order

I imagine that I must parameterize it in the mysql query, I currently have it that way, where the variable

$_POST["query"]

is the search term entered in the input

SELECT * FROM cuentas WHERE nombre_cliente LIKE '%".$_POST["query"]."%' ORDER BY nombre_cliente ASC
    
asked by Gabriel Uribe Gomez 27.03.2018 в 02:12
source

2 answers

1

Try using the distinct parameter within your SQL statement to help eliminate the repeated values from the list of results, like this:

SELECT distinct valor1, valor2 FROM cuentas WHERE nombre_cliente LIKE '%".$_POST["query"]."%' ORDER BY nombre_cliente ASC;

That if instead of using * pass the names of the columns you want to return

    
answered by 27.03.2018 в 02:31
0
SELECT DISTINCT column1 FROM table

This will bring back the only regimes of the field you want

    
answered by 27.03.2018 в 02:30