Created
July 3, 2012 18:49
-
-
Save SeanJA/3041858 to your computer and use it in GitHub Desktop.
drupal equivalent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT COUNT(*) | |
FROM table_1 | |
JOIN table_2 ON (table_1.id=table_2.table_1_id) | |
WHERE table_1.column != 'foo' | |
<?php | |
//query_builder | |
$q = new query($db); | |
$q->column('COUNT(*)') | |
->table('table_1') | |
->join('table_2', 'table_1.id=table_2.table_1_id') | |
//query::NOT_EQUAL === '!=' | |
->where('table_1.column', 'foo', query::NOT_EQUAL); | |
//drupal 7 version | |
//why is this so complicated and somewhat inconsistent? | |
//set the initial table | |
$query = db_select('table_1', 't1'); | |
//returns the table alias (t2 in this case) ? | |
//breaking the chain | |
$query->innerJoin('table_2', 't2', 't1.id=t2.table_1_id'); | |
//continue building the query (this part is chainable again) | |
$query->fields('', 'COUNT(*)') | |
->condition('table_1.column', "foo", '!='); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment