Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rudiedirkx
Last active September 20, 2015 18:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rudiedirkx/bee6219d0700b4663201 to your computer and use it in GitHub Desktop.
Save rudiedirkx/bee6219d0700b4663201 to your computer and use it in GitHub Desktop.
<?php
// SELECT a.*, c.d, (c.e = 'foo') AS ee, c.f AS ff
// FROM table1 a, table3 m
// LEFT JOIN table2 b ON a.x = c.x AND a.x <> '4'
// WHERE m.x = a.x AND a.y < 100 AND (a.z BETWEEN 1 AND 9 OR a.z = -1)
// GROUP BY (c.e = 'foo'), c.f
// HAVING MAX(m.n) > 2
// ORDER BY c.e DESC
// LIMIT 100
// OFFSET 100
$query = array(
// SELECT
'fields' => array(
'a' => array('*'),
'c' => array(
'd',
'ff' => 'f',
),
array(
'ee' => array('(c.e = ?)', 'foo'),
),
// @todo buildable sub query?
),
// 'fields' => 'a.b, c.d',
// FROM
'tables' => array('b' => 'table1', 'm' => 'table3'),
// 'tables' => 'table1 a, table3 m',
// @todo buildable sub query?
// X JOIN
'join' => array(
'b' => array(
'type' => 'left',
'table' => 'table2',
'conditions' => array( // %conditions%
'a.x = c.x',
array('a.x <> ?', 4),
// @todo buildable sub query?
),
),
),
// WHERE
'conditions' => array( // %conditions%
'and',
'm.x = a.x',
array('a.y', 100, '<'),
// @todo buildable sub query?
array(
'or',
array('a.z BETWEEN ? AND ?', 1, 9),
array('a.z', -1),
),
),
// GROUP BY
'group' => array(
array('(c.e = ?)', 'foo'),
'c.f',
// @todo buildable sub query?
),
// HAVING
'having' => array( // %conditions%
array('MAX(m.n) > ?', 2),
// @todo buildable sub query?
),
// ORDER
'order' => array(
'c.e' => 'desc',
// @todo buildable sub query?
),
// LIMIT
'limit' => 100,
// OFFSET
'offset' => 100,
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment