Thinkphp Left Join/Right Join 实例

第一个表为Comment表,第二个表为Reply表,
MYSQL上测试语句为:select a.*,b.* from comment a left join reply b on a.id=b.cid

//Left Join
$Blog->table(‘comment a’)->join(‘reply b on a.id=b.cid’)->field(‘a.*,b.*’)->order(‘id desc’)->limit(‘8’)->findall();

//Right Join
$Blog->table(‘comment a’)->join(array(‘right’,‘reply b on a.id=b.cid’))->field(‘a.*,b.*’)->order(‘id desc’)->limit(‘8’)->findall();


affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.