Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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:msqyl连接self和LIKE查询_Php_Mysql_Sql_Join - Fatal编程技术网

PHP:msqyl连接self和LIKE查询

PHP:msqyl连接self和LIKE查询,php,mysql,sql,join,Php,Mysql,Sql,Join,我使用下面的代码,但不工作 SELECT `oldTb`.`userId` FROM `user` AS oldTb JOIN `user` AS newTb WHERE `newTb`.`userPrivate` LIKE "%,`oldTb`.`userId`,%" GROUP BY `userId` 实际上,我希望当self表中的userPrivate列具有用户的、ID、时获得用户的结果 例如: userId ---- userPrivate 1 ---- ,0,

我使用下面的代码,但不工作

SELECT `oldTb`.`userId`
FROM `user` AS oldTb JOIN
     `user` AS newTb
WHERE `newTb`.`userPrivate` LIKE "%,`oldTb`.`userId`,%"
GROUP BY `userId`
实际上,我希望当self表中的
userPrivate
列具有用户的
、ID、
时获得用户的结果

例如:

userId ---- userPrivate    
1  ---- ,0,    
2 ---- ,0,    
3 ---- ,1,    
4 ---- ,1,3,    
5 ---- ,3,
现在必须得出的结果是:


1和3

我希望这不是一个关于逗号分隔数据的问题。您可以发布您的表结构吗?请参见
“%,`oldTb`.`userId`,%”
应为
CONCAT(“%,”,`oldTb`.`userId`,“,%”)
修复您的数据!您不应该将数字ID(应声明为外键)存储为分隔字符串中的字符值。这不是在关系数据库中存储数据的正确方法。