在之前的tp版本里都是在mode里进行表的关联,但是到了tp5开始就没有这个功能了
今天我就给大家介绍一下在tp5中怎样使用视图查询
视图查询是可以实现不依赖数据库视图的多表查询方法,并不需要数据库支持视图,例如:
这样生成的sql语句如下方
SELECT User.id,User.name,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User INNER JOIN think_profile Profile ON Profile.user_id=User.id INNER JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80
也可以进行别名的设置
生成下方语句
SELECT User.id AS uid,User.name AS account,Profile.truename,Profile.phone,Profile.email,Score.score FROM think_user User INNER JOIN think_profile Profile ON Profile.user_id=User.id INNER JOIN think_socre Score ON Score.user_id=Profile.id WHERE Score.score > 80
基本的用法大体这些,希望能帮助到大家