打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
ThinkPHP的多表查询

THINKPHP 中关联查询(多表查询)可以使用 table() 方法或和join方法,请看示例:

1、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();

2、join()

$user = new Model('user');

$list = $user->join('RIGHT JOIN user_profile ON user_stats.id = user_profile.typeid' );

3、原生查询

$Model = new Model();

$sql = 'select a.id,a.title,b.content from think_test1 as a, think_test2 as b where a.id=b.id '.$map.' order by a.id '.$sort.' limit '.$p->firstRow.','.$p->listRows;
$voList = $Model->query($sql);

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
ThinkPHP多表联合查询的常用方法
mysql 查询优化 in 和 not in
MySQL 多表左连接
hive的关联查询
MySql的join(连接)查询 (三表 left join 写法)
兄弟连go教程(19)数据
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服