分享到: ------解决方案-------------------- select * from `a` ,`b` where `a`.`bid` like concat('%',`b`.`bid`,'%')
如果要查a表id等于1对应的关联数据,可以写成
select * from `a` ,`b` where `a`.`id`='1' and `a`.`bid` like concat('%',`b`.`bid`,'%') ------解决方案--------------------
CREATE TEMPORARY TABLE a (id int, bid varchar(10), content varchar(10));<br />
INSERT INTO a VALUES('1','1,5,2','AAAAAAA');<br />
INSERT INTO a VALUES('2','2,4','AAAAAAA');<br />
INSERT INTO a VALUES('3','1,3,2','AAAAAAA');<br />
CREATE TEMPORARY TABLE b (bid int, content varchar(10));<br />
INSERT INTO b VALUES('1','BBBBB');<br />
INSERT INTO b VALUES('2','BBBBB');<br />
INSERT INTO b VALUES('3','BBBBB');<br />
INSERT INTO b VALUES('4','BBBBB');<br />
INSERT INTO b VALUES('5','BBBBB');<br />
select a.id, b.bid as bid, a.content, b.content as bcontent<br />
from a, b<br />
where find_in_set(b.bid, a.bid)<br />
order by a.id
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn