Thinkphp 多表查询 join table用法 同名字段查询

ThinkPHP常用的两个多表查询方法,table() join()

table

	
$list = M()->table('user1 a, user2 b')->where('a.id = b.id')->field('a.name,b.sex')->order('a.id desc')->select();

join
$pre = C('DB_PREFIX');
M("user u")->join("{$per}user_info x ON x.uid = u.id")->where("u.id = $uid")->find();

另外,两个表中若有同名字段都要查询的话,用这样的写法:  filed('a.*,b.name as username,b.sex')

记录官网的一篇教程
http://www.thinkphp.cn/topic/9332.html

猜你喜欢

转载自blog.csdn.net/first236108/article/details/77417266