Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 检查两个独立行的列,如果相同,则返回true_Php_Mysql - Fatal编程技术网

Php 检查两个独立行的列,如果相同,则返回true

Php 检查两个独立行的列,如果相同,则返回true,php,mysql,Php,Mysql,我想知道是否可以在mysql端(从查询中)进行检查,看看是否有两个不同的唯一ID的列匹配。已经用php解决了这个问题,但如果可能的话,我想简化它 我说这是什么 product | attribute_1 | attribute_2 | attribute_3 ------------------------------------------------- 1 10 20 30 2 10 20

我想知道是否可以在mysql端(从查询中)进行检查,看看是否有两个不同的唯一ID的列匹配。已经用php解决了这个问题,但如果可能的话,我想简化它

我说这是什么

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
)