Home > Database > Mysql Tutorial > MySQL多表之间字段的匹配实现代码

MySQL多表之间字段的匹配实现代码

WBOY
Release: 2016-06-07 17:55:31
Original
961 people have browsed it

本文主要介绍下MySQL多表之间字段的匹配;如tag表中name匹配info中的name,接下来详细介绍下,感兴趣的你可以参考下哈

代码如下:
$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['lianxi'];
$dizhi=$r['dizhi'];
}

如下:两个表info,tag
info 表
id name
1 aa和bb
2 bb和cc
3 ee和dd
tag表
1 aa
2 bb
tag表中 name 匹配 info 中的name
这样写就有问题:
代码如下:
select info.id, info.name from tag,info where info.name like ‘%'+tag.name+'%'

正确:
代码如下:
select info.id, info.name from tag,info where info.name like concat( '%',tag.name, '%')
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template