简体   繁体   中英

select only distinct values - MYSQL

I have a column in my database that is entitled area and when users register they pick an area from 6 options. When I try to setup a search that shows people from those areas using a dropdown menu it duplicates them and only shows one result when the form is submitted.

SELECT * FROM registration ORDER BY area is my query and in the dropdown it produces results like:

Warwickshire
Warwickshire
Warwickshire
Northamptonshire

etc. but I want it to just show Warwickshire once and when you click submit it shows all the people from Warwickshire instead of just the one user.

Any help is appreciated, thanks Richard.

尝试这个

"SELECT * FROM registration GROUP BY <repeating_column_name> ORDER BY area" 

SELECT DISTINCT area FROM registration ORDER BY area

use distinct clause to get you the uniq data. You can' apply distinct to * ; specify the particular column you are trying to get. Your case, if it's area then try

select distinct area from registration order by area;

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