1、delete 的左连接:
$DeleteSql = "delete contract_text
from contract_text left join contract on contract_text.ID=contract.ContractTextID
where contract_text.UserID={$_SESSION['User']['ID']} and contract_text.Flag<>1";
2、select中的一表查询
$sql = "select handling.RealName as Handling, person.RealName as Person
from user as handling
left join user person on handling.Manager = person.ID
left join contract on contract.UserID=handling.ID
where contract.ID={$EditID}";
说明:在user表中有一个RealName字段,每条记录又有一个管理员ID,即父记录,全部在一个表中存在,此时查询该当如上述。此时必须给user表两个别名,否则不能查询。
又一个select查询
$sql = "select city.Title, city.Address, city.Tel, city.Fax,
city.Bank, city.BankUseName, city.BankCount, city.Sign,
handling.RealName as Handling, person.RealName as Person
from user as handling
left join user person on handling.Manager = person.ID
left join contract on contract.UserID=handling.ID
left join city on handling.CityID=city.ID
where contract.ID={$EditID}"
转载请注明:谷谷点程序 » MySQL中的左连接