Php 检查两个独立行的列,如果相同,则返回true
我想知道是否可以在mysql端(从查询中)进行检查,看看是否有两个不同的唯一ID的列匹配。已经用php解决了这个问题,但如果可能的话,我想简化它 我说这是什么Php 检查两个独立行的列,如果相同,则返回true,php,mysql,Php,Mysql,我想知道是否可以在mysql端(从查询中)进行检查,看看是否有两个不同的唯一ID的列匹配。已经用php解决了这个问题,但如果可能的话,我想简化它 我说这是什么 product | attribute_1 | attribute_2 | attribute_3 ------------------------------------------------- 1 10 20 30 2 10 20
product | attribute_1 | attribute_2 | attribute_3
-------------------------------------------------
1 10 20 30
2 10 20 31
3 10 20 30
因此,对于1-3
,它将返回true;对于1-2
或1-3
,它将返回false。您可以使用:
SELECT atribute_1, atribute_2, atribute_3, count(*) as `Count of duplicated rows`
FROM YOUR_TABLE group by atribute_1, atribute_2, atribute_3
SELECT
(SELECT attribute1, attribute2, attribute3 FROM t WHERE product=$id1)
=
(SELECT attribute1, attribute2, attribute3 FROM t WHERE product=$id2)
-i、 检查元组是否相等。例如,您的
$id1
和$id2
都是从应用程序派生的。您也可以使用此选项:
select exists (
select 1 from TableName t1, TableName t2
where
t1.`Attribute_1` = t2.`Attribute_1` and
t1.`Attribute_2` = t2.`Attribute_2` and
t1.`Attribute_3` = t2.`Attribute_3` and
t1.`Product` = $id1 and
t2.`Product` = $id2
)