- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Join Method
The join method is used to combine query results from two or more tables with only 1 key is to be joined as condition.
This method will execute the JOIN SQL command as well as part of the Query Builder.
Basic Usage
Here is the basic usage join method from $db property on SENE_Model class.
$this->db->join(
string $table2,
string $table2_alias,
string $table2_column_to_joined,
string $table1_alias,
string $table1_column_to_joined
[, string $join_method = ""]
): $this->dbParameters
This method has 5 required parameters and 1 optional parameter.
$table2
The $table2 refers to the name of the table that will be joined to.
$table2_alias
The $table2_alias value can contain about string that aliased the value of $table2.
$table2_column_to_joined
The $table2_column_to_joined value can contain about column name from $table2 to be the key.
$table1_alias
The $table1_alias value can contain about string that aliased the value of origin table.
$table1_column_to_joined
The $table1_column_to_joined value can contain about column name from origin table to be the key.
$join_method
The $join_method purpose is to declare join method that used.
Default value is the empty string "".
Or can be on of these value:
leftrightinnerouter
Example
The following is an example of using the join method in the d_order_model.php file.
<?php
class D_Order_Model extends SENE_Model{
public $table = 'd_order';
public $table_alias = 'dor';
public $table2 = 'd_order_detail';
public $table2_alias = 'dod';
public $table3 = 'c_produk';
public $table3_alias = 'cp';
public function __construct(){
parent::__construct();
$this->db->from($this->table,$this->table_alias);
}
public function getByOrderId($d_order_id){
$this->db->from($this->table,$this->table_alias);
$this->db->join($this->table2, $this->table2_alias, 'id', $this->table_alias, 'd_order_id', 'left');
$this->db->where_as("$this->table_alias.d_order_id", $this->db->esc($d_order_id));
return $this->db->get();
}
public function getDetailJasaForDrDashboard(){
$this->db->from($this->table, $this->table_alias);
$this->db->join($this->table2, $this->table2_alias, 'id', $this->table_alias, 'd_order_id', '');
$this->db->join($this->table3, $this->table3_alias, 'id', $this->table_alias, 'c_produk_id', 'left');
$this->db->where_as("$this->table2_alias.utype",$this->db->esc('order_selesai'));
$this->db->where_as("$this->table3_alias.jenis_paket", 'IS NULL');
$this->db->where_as("$this->table_alias.sdate", 'IS NOT NULL');
return $this->db->get('',0);
}
}SQL Generated Result
The following is the SQL command generated by the method in the D_Order_Model class example.
-- result from executing D_Order_Model::getByOrderId(47) --
SELECT *
FROM `d_order` dor
LEFT JOIN d_order_detail dod
ON dor.id = dod.d_order_id
WHERE dod.`id` = 47;
-- result from executing D_Order_Model::getDetailJasaForDrDashboard() --
SELECT *
FROM `d_order` dor
JOIN d_order_detail dod
ON dor.id = dod.d_order_id
LEFT JOIN c_produk cp
ON cp.id = dod.c_produk_id
WHERE
dod.`utype` = "order_selesai"
AND cp.utype IS NULL
AND dor.sdate IS NOT NULL;