function db_distinct_field
6.x database.inc | db_distinct_field($table, $field, $query) |
Adds the DISTINCT flag to the supplied query and returns the altered query.
The supplied query should not contain a DISTINCT flag. This will not, and never did guarantee that you will obtain distinct values of $table.$field.
Parameters
$table: Unused. Kept to retain API compatibility.
$field: Unused. Kept to retain API compatibility.
$query: Query to which the DISTINCT flag should be applied.
Return value
SQL query with the DISTINCT flag set.
Related topics
1 call to db_distinct_field()
- db_rewrite_sql in drupal-6.x/
includes/ database.inc - Rewrites node, taxonomy and comment queries. Use it for listing queries. Do not use FROM table1, table2 syntax, use JOIN instead.
File
- drupal-6.x/
includes/ database.inc, line 407 - Wrapper for database interface code.
Code
function db_distinct_field($table, $field, $query) {
$matches = array();
if (!preg_match('/^SELECT\s*DISTINCT/i', $query, $matches)) {
// Only add distinct to the outer SELECT to avoid messing up subqueries.
$query = preg_replace('/^SELECT/i', 'SELECT DISTINCT', $query);
}
return $query;
}