以下内容很好的举例了thinkphp中的join方法,一些常见的联合查询操作基本包括 了!
JOIN方法是连贯操作中唯一可以多次调用的方法
分别查询表artist、work、card 、card
JOIN 有两种方式:LEFT JOIN(默认使用)与RIGHT JOIN
//Left Join
$Model->join(\'work ON artist.id = work.artist_id\')->join(\'card ON artist.card_id = card.id\')->select();
$Model->table(\'user U\')->join(\'news N on U.id=N.cid\')->field(\'U.*,N.*\')->order(\'id desc\')->limit(\'8\')->select();
//Left Join
$Model->table(\'user U\')->join(\'news N on U.id=N.cid\')->field(\'U.*,N.*\')->order(\'id desc\')->limit(\'8\')->select();
//Right Join
$Model->join(\'RIGHT JOIN work ON artist.id = work.artist_id\')->select();
$Model->table(\'user U\')->join(array(\'right\',\'news N on U.id=N.cid\'))->field(\'U.*,N.*\')->order(\'id desc\')->limit(\'8\')->select();