Re: Make optimized LEFT JOIN with GROUP BY
You can use SQL_CALC_FOUND_ROWS instead, MySQL will then calculate how many rows there were without a LIMIT clause. Then you can fetch that value using FOUND_ROWS().
mysql> select * from b;
+------+------+
| id | cat |
+------+------+
| 1 | 1 |
| 1 | 4 |
| 2 | 1 |
| 3 | 4 |
| 3 | 10 |
+------+------+
5 rows in set (0.00 sec)
mysql> SELECT SQL_CALC_FOUND_ROWS * FROM b WHERE cat = 4 LIMIT 1;
+------+------+
| id | cat |
+------+------+
| 1 | 4 |
+------+------+
1 row in set (0.00 sec)
mysql> SELECT FOUND_ROWS();
+--------------+
| FOUND_ROWS() |
+--------------+
| 2 |
+--------------+
Subject
Views
Written By
Posted
12627
May 03, 2006 08:30AM
5303
May 03, 2006 09:11AM
4214
May 03, 2006 09:20AM
3678
May 03, 2006 09:21AM
5987
May 03, 2006 01:19PM
4063
May 03, 2006 02:38PM
2563
May 03, 2006 02:43PM
3650
May 03, 2006 03:35PM
3579
May 03, 2006 12:58PM
2456
May 03, 2006 01:17PM
2389
May 03, 2006 01:23PM
2321
May 03, 2006 04:03PM
2193
May 03, 2006 04:17PM
4319
May 03, 2006 04:29PM
2402
May 03, 2006 05:09PM
2530
May 03, 2006 05:45PM
Re: Make optimized LEFT JOIN with GROUP BY
2541
May 03, 2006 06:41PM
2305
May 04, 2006 06:05AM
3869
May 04, 2006 08:10AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.