I want to do a simple SQL query in Drupal, but I’m not sure how. I would like to achieve this:
SELECT COUNT(nid) AS i_count FROM node WHERE `created` != `changed`;
I have the following code, which doesn’t work:
$query = db_select('node', 'n');
$query->addExpression("COUNT(nid)","i_count");
$query->condition("created","changed","!=");
$i_number_published = $query->execute()->fetchCol();
The reason why it doesn’t work is that it compares the column created with the string value "changed". Is there any way I can tell it to compare columns instead of column-string?
Use the
where()member function to add conditions based on other fields in the table: