『MySQL』多表之间字段的匹配

来源:互联网 发布:mac pro 无法安装win7 编辑:程序博客网 时间:2024/06/06 17:38
1 $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]."");2 while($r=$empire->fetch($sql))3 {4         $title=$r['title'];5         $lianxi=$r['lianxi'];6         $dizhi=$r['dizhi'];7 }

如下:两个表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, '%')

 


<script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* cnblogs 首页横幅 */google_ad_slot = "5419468456";google_ad_width = 728;google_ad_height = 90;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>