Generally, what is the most efficient way to get a Yes/No answer as to whether there is at least 1 result to a query:
$db->query("SELECT COUNT(*) AS total FROM x WHERE Y");
$result = $db->get_row();
if ($result['total'] > 0) {
...
} else {
}
or:
$db->query("SELECT j AS y FROM x WHERE Y LIMIT 1");
if ($db->num_rows()) {
...
} else {
}
Does it make any difference? My guess is the 2nd is more efficient because it only scans one row, can a COUNT(*) be made to only scan for 1 row?








Bookmarks