MySQL implementation code for matching fields between multiple tables

  • 2020-05-15 02:24:01
  • OfStack

 
$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']; 
} 

As follows: two tables info, tag
info table
id name
1 aa and bb
2 bb and cc
3 ee and dd
tag table
1 aa
2 bb
name in the tag table matches name in info
The problem with this is:
 
select info.id, info.name from tag,info where info.name like  ' %'+tag.name+'%' 

Correct:
 
select info.id, info.name from tag,info where info.name like concat( '%',tag.name, '%') 

Related articles: