Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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
Mysql 与where和contains子句联接_Mysql_Sql - Fatal编程技术网

Mysql 与where和contains子句联接

Mysql 与where和contains子句联接,mysql,sql,Mysql,Sql,我无法编写需要连接两个表并获取这两个表的公共值的sql查询 像这样的, select control_id from ProjectImage where group_id ="20" Join (select images from coupon where coupon_name is "test" and images contains control_id of projectImage) images是由逗号分隔的控件id列表 因此,最后我只需要优惠券的表映像列中存在的那些控制ID

我无法编写需要连接两个表并获取这两个表的公共值的sql查询

像这样的,

select control_id from ProjectImage
where group_id ="20"
Join
(select images from coupon where coupon_name is "test" and images contains control_id of projectImage)
images是由逗号分隔的控件id列表

因此,最后我只需要优惠券的表映像列中存在的那些
控制ID

ProjectImage table ---- 
         image_id   bigint(20)  
    control_id  varchar(255)
    name    varchar(255)
    project_id  bigint(20)      
    group_id    bigint(20)

Coupon table:
    id  bigint(20)  
    image   varchar(1250)   
    name    varchar(255)    
    status  int(11)     
    wafer_id    bigint(20)

您可以在某些键(例如主键)上联接表,也可以使用

select control_id from ProjectImage where group_id ="20" and
control_id contains(select images from coupon where coupon_name is
"test" and images contains control_id)

如果我没有弄错你的问题,你的问题应该是这样的

SELECT ProjectImage.control_id, coupon.images
FROM ProjectImage
JOIN coupon ON ProjectImage.control_id = coupon.control_id
WHERE ProjectImage.group_id ="20"
    AND coupon.coupon_name = 'test'
如果不能这样做,请为我们提供ProjectImage和优惠券的表结构

编辑
使用提供的结构,您可以跟踪并将列映像拆分为单独的行,然后使用临时联接,例如在临时表上

选择表1中的字段联接表2,首先是MySql还是Sql Server?第二,联接应该在where子句之前,这可能是的重复项,因此优惠券表中的外键位于由逗号分隔的控件ID列表中?这就是你想要连接这两个表的方式?@RagingBull是的,但我不确定这是否可能。这两个表中没有相同的列。唯一的问题是projectImage表的控件id是优惠券表中图像的子集。@PSDebugger如果没有公共列,则不能使用join。唯一的问题是控件id在图像中(图像是不同id的集合,其中控件id将是其中之一)。因此,我需要比较ProjectMage表中的控件id是否在images列中,然后返回该值。@PSDebugger您能给我们提供表结构吗?问题中添加的包含require列和文本,但在这里它无法解析第二个查询