How can I read the data in table A from A join query statement? (At the same time, you must read the corresponding data in B.) ask a statement for joint query.
As shown in
How can I read the data in? (At the same time, you need to read the corresponding data in B.) share:
------ Solution --------------------
Select * from 'A', 'B' where 'a'. 'bid' like concat ('%', 'B'. 'bid', '% ')
If you want to query the associated data with table a whose id is equal to 1, you can write it
Select * from 'A', 'B' where 'a '. 'id' = '1' and 'A '. 'bid' like concat ('%', 'B '. 'bid', '% ')
------ Solution --------------------
CREATE TEMPORARY TABLE a (id int, bid varchar(10), content varchar(10));
INSERT INTO a VALUES('1','1,5,2','AAAAAAA');
INSERT INTO a VALUES('2','2,4','AAAAAAA');
INSERT INTO a VALUES('3','1,3,2','AAAAAAA');
CREATE TEMPORARY TABLE b (bid int, content varchar(10));
INSERT INTO b VALUES('1','BBBBB');
INSERT INTO b VALUES('2','BBBBB');
INSERT INTO b VALUES('3','BBBBB');
INSERT INTO b VALUES('4','BBBBB');
INSERT INTO b VALUES('5','BBBBB');
select a.id, b.bid as bid, a.content, b.content as bcontent
from a, b
where find_in_set(b.bid, a.bid)
order by a.id