选择没有重复条目的一行
在 mysql 表 info
我有:
In mysql table info
i have :
Id、姓名、城市、日期、状态
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.
说:在原始name"下,我们已经插入了 10 次John"这个名字.
我只想回声一次.这可能吗?
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.
相关文章