Ask a joint query statement

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.