例如我要查询的原生sql语句为:
select a.*,b.* from user as a left join userinfo as b on a.id=b.uid
thinkphp里面可以写为:
$result = M('user')->table('user as a')->join('userinfo as b on a.id=b.id')->field('a.*,b.*')->select();
或者写为:
$result = M('user')->join('RIGHT JOIN userinfo ON user.id=userinfo.id')->field('a.*,b.*')->select();
或者也可以自己组合SQL语句,写为:
$db = M(''); $sql = "select a.*,b.* from user as a left join userinfo as b on a.id=b.uid"; $result = $db->query($sql);