THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例:
联合查询
1、原生查询
$sql = 'select f.*,s.sort_name from think_form as f, think_sort as s where f.sort_id=s.sort_id order by f.id DESC limit 3';
$list = $Form->query($sql);
2、join() 两表查询
$list = $Form->join('think_sort ON think_form.sort_id = think_sort.sort_id' )->select();
3、join() 多表查询
$list = $Form->join('think_sort ON think_form.sort_id = think_sort.sort_id' )->join('think_brand ON think_form.brand_id = think_brand.brand_id' )->select();
4、table()
$list = $user->table('user_status stats, user_profile profile')->where('stats.id = profile.typeid')->field('stats.id as id, stats.display as display, profile.title as title,profile.content as content')->order('stats.id desc' )->select();
转载于:https://blog.51cto.com/mickelfeng/1034654