[英]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. 我的数据库中有一列名为区域的列,当用户注册时,他们从6个选项中选择一个区域。 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: SELECT * FROM registration ORDER BY area
是我的查询,在下拉列表中它产生如下结果:
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. 等等,但我希望它只显示一次Warwickshire,当您单击“提交”时,它显示了Warwickshire的所有人,而不仅仅是一个用户。
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. 使用
distinct
子句获取uniq数据。 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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.