使用GROUP BY语句但仍显示重复项

时间:2017-01-03 09:57:24

标签: mysql

试图从表中调出每种类型的项目,我已经在我的sql查询中放入group by语句但它仍然回显出重复的数据。

这是代码和数据库示例

<?php
$con=mysqli_connect("localhost","root","root","test");
$sql = "SELECT * FROM testing GROUP BY Name";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_array($result)) {
    echo $row['name'];
    echo "<br>";
}
?>

database

2 个答案:

答案 0 :(得分:0)

以下是您可以尝试的代码..

<?php
     $con=mysqli_connect("localhost","root","root","test");
     $sql = "SELECT distinct name, Record_ID, Shop_ID  FROM testing";
     $result = mysqli_query($con, $sql);
     while($row = mysqli_fetch_array($result))
     {
         echo $row['name'];
            echo "<br>";

     }
?>

答案 1 :(得分:0)

试试这个: -

 Select distinct name from testing;