ThinkPHP聯表查詢

來源:互聯網
上載者:User

標籤:表名   where   查詢   nbsp   use   res   欄位   bsp   php   

1、table 方法

  

  原生sql方法

  原生sql文法:select 表1.欄位,表2.欄位 from 表1as 別名1,表名2 as 別名 2 where 表1.欄位 = 表2.欄位;

  select t1.*,t2.name as deptname from sp_user as t1,sp_dept as t2 where t1.dept_id = t2.id;

 

  $model -> table(‘表名1[as 別名1],表名2[as 別名2]……‘);

  $result = $model -> field(‘t1.*,t2.name as deptname‘) -> table(‘sp_user as t1,sp_dept as t2‘) -> where(‘t1.dept_id = t2.id‘) -> select();

2 、join方法

  select 表1.欄位,表2.欄位 from 表1 as 別名[inner/left/right] join 表2 as 別名 on 表1.欄位 = 表2.欄位;

  原生的sql:select t1.*,t2.name as deptname from sp_dept as t1 left join sp_dept as t2 on t1.pid;

ThinkPHP聯表查詢

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.