Code for matching fields between multiple MySQL tables

Source: Internet
Author: User
This article describes how to match fields in multiple MySQL tables. For example, the name in the tag table matches the name in info. For more information, see

This article describes how to match fields in multiple MySQL tables. For example, the name in the tag table matches the name in info. For more information, see

The 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:
The Code is as follows:
Select info. id, info. name from tag, info where info. name like '%' + tag. name + '%'

Correct:
The Code is as follows:
Select info. id, info. name from tag, info where info. name like concat ('%', tag. name, '% ')

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.