Code for matching fields between multiple MySQL tables

Source: Internet
Author: User

CopyCodeThe Code is as follows: $ SQL = $ empire-> query ("select table. title, lianxi, table. dizhi, table. ID from table, Table1 where table1.sid like Concat ('% |', table. ID, '| %') and table1.id = ". $ navinfor [ID]. "");
While ($ r = $ empire-> fetch ($ SQL ))
{
$ Title = $ R ['title'];
$ Lianxi = $ R ['liance'];
$ Dizhi = $ R ['dizhi'];
}

The two tables info and tag are as follows:
Info table
ID name
1 aa and BB
2 BB and CC
3 EE and dd
Tag table
1 aa
2 bb
The name in the tag table matches the name in info.
In this case, there is a problem:Copy codeThe Code is as follows: Select info. ID, info. name from tag, info where info. name like '%' + tag. Name + '%'

Correct:Copy codeThe Code is as follows: Select info. ID, info. name from tag, info where info. name like Concat ('%', tag. Name, '% ')

Related Article

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.