您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

thinkPHP3.2 中join用法实例

2024/3/16 15:13:28发布34次查看
inner join  如果表中至少 有一个匹配,在则返回行,等同与 join 。
left    join  即使 有右表中没有匹配 ,也从左表中返回所有的行。
right join  即使左表中没有匹配,也从右表中返回所有的行。
full    join  只要其中一个表中匹配,就返回行。
 $lists = $this->ordermodel      ->alias('t')      ->field('t.*,o.order_id as ccsid')       ->join('left join __order__ as o on t.order_id = o.third_order_id  and t.source = o.source')       ->where($map)       ->order(create_time desc)       ->limit($page->firstrow . ',' . $page->listrows)       ->select();
tp语法注释:
$lists = $this->ordermodel              // m('third_order');     ->alias('t')                        // 别名     ->field('t.*,o.order_id as ccsid')  // 要查的字段     ->join('left join __order__ as o on t.order_id = o.third_order_id  and t.source = o.source')     //关联表(左链接  order表 as o 别名  on关系 t.xx = o.xxx          and  t.xxx  =  o.xxx  )     ->where($map)                       // 条件     ->order(create_time desc)         // 排序     ->limit($page->firstrow . ',' . $page->listrows)  // 取几条     ->select();
解析的sql 语句为:
select t.*,o.order_id as ccsid from db_third_order t left join db_order as o on t.order_id = o.third_order_id and t.source = o.source where t.status <> 0 order by create_time desc limit 0,20
原生sql注释 :
select 表名(别名).* , 表名(别名). 字段 as 别名 from 主表 空格 别名(t) left join 从表 as 别名 (o) on t.xxx = o.xxx and t.xxx = o.xxx <表关系> where 条件 order by 字段名 desc 倒叙 limit 0,20
相关推荐:
实例详解javascript中split与join的区别
javascript把数组中的所有元素放入一个字符串的方法join()
php join函数的使用代码实例
以上就是thinkphp3.2 中join用法实例的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product