Ivory ORM Docs

Ivory ORM Docs

  • Docs

›SQL Syntax

SQL Syntax

  • First-Steps
  • Select
  • Select Distinct
  • Where
  • And, Or and Not
  • Order By
  • Insert
  • Update
  • Delete
  • Min and Max
  • Count, Avg and Sum
  • Like
  • In
  • Between
  • Alias
  • Joins
  • Union
  • Group By
  • Having
  • Exists
  • Any & All
  • Procedures

Joins

Joins

The steps to made joins in your query using ivory are very simple and takes just some parameters.

Example Inner Join

require_once('Operations.php');

$ivoryOrm = new Operations();

$arrSelect[] = "users.name";
$arrSelect[] = "customers.id";

$tables[] = "users";

//the method select creates the query : SELECT users.name,customers.id FROM users INNER JOIN customers ON users.id = customers.id;
$select = $ivoryOrm->select($arrSelect, $tables);
$innerJoin = $ivoryOrm->innerJoin($select, "customers","users.id", "customers.id");

//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($innerJoin);

Example Left Join

require_once('Operations.php');

$ivoryOrm = new Operations();

$arrSelect[] = "users.name";
$arrSelect[] = "customers.id";

$tables[] = "users";

//the method select creates the query : SELECT SELECT users.name,customers.id FROM users LEFT JOIN customers ON users.id = customers.id;
$select = $ivoryOrm->select($arrSelect, $tables);
$leftJoin = $ivoryOrm->leftJoin($select, "customers","users.id", "customers.id");

//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($leftJoin);

Example Right Join

require_once('Operations.php');

$ivoryOrm = new Operations();

$arrSelect[] = "users.name";
$arrSelect[] = "customers.id";

$tables[] = "users";

//the method select creates the query : SELECT SELECT users.name,customers.id FROM users RIGHT JOIN customers ON users.id = customers.id;
$select = $ivoryOrm->select($arrSelect, $tables);
$rightJoin = $ivoryOrm->rightJoin($select, "customers","users.id", "customers.id");

//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($rightJoin);

Example Full Outer Join

require_once('Operations.php');

$ivoryOrm = new Operations();

$arrSelect[] = "users.name";
$arrSelect[] = "customers.id";

$tables[] = "users";

//the method select creates the query : SELECT SELECT users.name,customers.id FROM users FULL OUTER JOIN customers ON users.id = customers.id;
$select = $ivoryOrm->select($arrSelect, $tables);
$fullOuterJoin = $ivoryOrm->fullOuterJoin($select, "customers","users.id", "customers.id");

//the method runQuery is responsible to literally run your query into the database;
$result = $ivoryOrm->runQuery($fullOuterJoin);

← AliasUnion →
  • Joins
  • Example Inner Join
  • Example Left Join
  • Example Right Join
  • Example Full Outer Join
Repository Link
Copyright © 2020 Kevin da Silva