Select only unique row/record in mysql

后端 未结 4 500
我在风中等你
我在风中等你 2021-01-12 21:47

I would like to see how I can get only unique row/records that have a unique city and not care if it\'s capital so for example:

Akron
akron
aKRON

4条回答
  •  遥遥无期
    2021-01-12 22:35

    It doesn't work on other DBMS, but in MySql you could use this:

    SELECT city, state_prefix,lattitude,longitude
    FROM zip_code WHERE city LIKE '$queryString%'
    GROUP BY city
    LIMIT 10
    

    MySql ignores case when comparing strings, e.g. this returns true:

    select 'hello'='Hello '
    

    and you can also group by a single field (city in this case) and return all others field. Values of other fields are undetermined, they are usually the ones in the first row but you can't relay on that.

提交回复
热议问题