inner join If there is at least one match in the table, rows are returned, which is equivalent to join.
left join Returns all rows from the left table even if there is no match in the right table.
right join Returns all rows from the right table even if there is no match in the left table.
full join Returns rows as long as there is a match in one of the tables.
$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 syntax comment:
$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();
The parsed sql statement is:
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
Native sql comment:
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
Related recommendations :
Example to explain the difference between split and join in JavaScript
JavaScript method join() to put all elements in an array into a string )
php join function usage code example
The above is the detailed content of Examples of join usage in thinkPHP3.2. For more information, please follow other related articles on the PHP Chinese website!