选择一行没有重复条目 [英] Select one row without duplicate entries

查看:15
本文介绍了选择一行没有重复条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 mysql 表 info 我有:

In mysql table info i have :

身份证、姓名、城市、日期、状态

Id , Name , City , date , status

我想从信息"中选择所有名称进行查询

I want to select all names from "info" Making the query

$query = mysql_query("SELECT name FROM info WHERE status = 1 ORDER BY id") 
         or die(mysql_error());

while ($raw = mysql_fetch_array($query)) 
{
  $name = $raw["name"];
  echo ''.$name.'<br>';
}

嗯,结果是它返回了所有条目.我想回显所有条目而不重复.

Well, the result is that it returns all the entries. I want to echo all the entries without duplicates.

说:在原始名称"下,我们已将名称约翰"插入了 10 次.
我只想回声一次.这可能吗?

Saying: under raw "name" we have inserted the name "John" 10 times.
I want to echo only one time. Is this possible?

推荐答案

很简单:

SELECT DISTINCT name FROM info WHERE status = 1 ORDER BY id

SQL 关键字 DISTINCT 可以解决问题.

The SQL keyword DISTINCT does the trick.

这篇关于选择一行没有重复条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆