I have a simple table called "board" that has a column called "sid" - that is just integers. Many of these are duplicates. I want to know only distinct values in this column, so I do this:
SELECT sid FROM board GROUP BY sid
When I run this query directly in phpMyAdmin, I get the set I was expecting. No problem. However, this bit of code returns every row in the entire table, without exception:
$sql = "SELECT sid FROM board GROUP BY sid"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ echo $row["sid"] . "<br />"; }
Does anyone know why? FYI I've tried every combination of DISTINCT and GROUP BY I could think of, but no matter what I do, I can't get a distinct set to echo out.
这听起来像是很奇怪的行为,但是为什么不试试这个:
select distinct sid from board
ACK. PEBKAC, sorry. Thanks for all the help. I didn't realize I had it nested in another loop and so the distinct resultset was actually echoing out multiple times.
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.