I need get specific values and count all values from a MySQL table, i need get the best performance, my question is: What is better and faster?
- Use two separate queries:
$TBCount = $Resps = $MySQL->query('SELECT COUNT(*) FROM T1');
$Resps = $MySQL->query('SELECT id, name FROM T1 LIMIT 1');
while ($Resp = $Resps->fetch_assoc()) {
...
}
- Use One query with two SELECT:
$Resps = $MySQL->query('SELECT id, name, (SELECT COUNT(*) FROM T1) AS count FROM T1 LIMIT 1');
while ($Resp = $Resps->fetch_assoc()) {
$TBCount = $Resp['count'];
...
}
- Or someone have some best idea?
In the case of "One query, two SELECT", in the "while" loop, how can i get the count value outside of the loop? (to avoid unnecessary rewrite of the variable).