[英]DISTINCT * is not withdrawing the duplicity (MYSQL)
i already done everything to remove this duplicity on the database On selecting a checkbox on the sectio "Bairros" i utilized as Array 我已经做了所有事情来消除数据库上的这种重复性。在选中“ Bairros” sectio上的复选框时,我将其用作数组
for($m=0; $m<count($_POST["bairros"]); $m++){// LOOP 1
$pesquisar=($_POST["bairros"][$m]);
//Copy bairros(Array) and esporte (POST)
$query = "SELECT DISTINCT * FROM cadastro WHERE
(esporte1 = '".$_POST["esportes"]."' OR
esporte2 = '".$_POST["esportes"]."' OR
esporte3 = '".$_POST["esportes"]."' OR
esporte4 = '".$_POST["esportes"]."')
AND
(bairro1 = '".$pesquisar."' OR
bairro2 = '".$pesquisar."' OR
bairro3 = '".$pesquisar."' OR
bairro4 = '".$pesquisar."')
AND
ativarAparecer='sim' ORDER BY nomeCompleto ASC LIMIT 20";
$esporte= new consultar();
$esporte->executa($query);
//Loops
for($l=0; $l<$esporte->nrw; $l++){ //LOOP 2
echo $esporte->data["nomeCompleto"]."<br />";
$esporte->proximo();
} //close LOOP2
} //close LOOP1
SELECT DISTINCT *
Stop There. 到此为止。 DISTINCT *
can do what? DISTINCT *
可以做什么? Duplicate of what? 重复什么? it cant do that. 它不能做到这一点。 Give it a field name to see unique values. 给它一个字段名称以查看唯一值。
For example 例如
SELECT DISTINCT nomeCompleto
Let's break this down. 让我们分解一下。 The DISTINCT
clause will return unique sets based on the selected columns . DISTINCT
子句将基于所选列返回唯一集 。
Let's say you have a table: 假设您有一张桌子:
a | b | c
=========
1 | 2 | 3
1 | 1 | 3
1 | 2 | 4
Now if you SELECT DISTINCT a FROM table
, you would get: 现在,如果您SELECT DISTINCT a FROM table
,您将得到:
1
but if you SELECT DISTINCT a, b FROM table
, you would get: 但是,如果您SELECT DISTINCT a, b FROM table
,则会得到:
a | b
=====
1 | 2
1 | 1
That's because {1,2}
is different from {1,1}
, even though the a
column is the same between those two sets. 这是因为{1,2}
与{1,1}
{1,2}
是不同的,即使这两个集合之间的a
列相同。
Obviously, doing SELECT DISTINCT * FROM table
would give you the original table because it uses all three columns as a "composition" of the unique set. 显然,执行SELECT DISTINCT * FROM table
将为您提供原始表,因为它使用所有三列作为唯一集的“组成”。 If we amended the table to look like this: 如果我们将表格修改为如下所示:
a | b | c
=========
1 | 2 | 3
1 | 1 | 3
1 | 2 | 4
1 | 2 | 3
Then your result of SELECT DISTINCT * FROM table
would give: 然后,您的SELECT DISTINCT * FROM table
将给出:
a | b | c
=========
1 | 2 | 3
1 | 1 | 3
1 | 2 | 4
because of the duplicate result set of {1, 2, 3}
. 由于{1, 2, 3}
的重复结果集。 However, since most tables have an auto-incrementing identifier as the primary key, there is almost always no difference between SELECT *
and SELECT DISTINCT *
. 但是,由于大多数表都具有自动递增的标识符作为主键,因此SELECT *
和SELECT DISTINCT *
之间几乎始终没有区别。
Perhaps you're looking to GROUP BY
a certain column? 也许您正在寻找按某列GROUP BY
的GROUP BY
?
How would I be using GROUP this in my script? 我将如何在脚本中使用GROUP GROUP? Column that there are several equal records are this bairro, bairro2, bairro3, bairro4. 这个Bairro,bairro2,bairro3,bairro4有几个相等记录的列。 Inside it is in numbers 里面是数字
bairro1 | bairro2 | bairro3 | bairro4
14 | 14 | 15 | 27
34 | 15 | 14 | 30
27 | 45 | 12 | 14
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.