选择一行没有重复条目
在 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.
相关文章