For example Table x have 9 records
x = 5
I make query:
Select * From `x` LIMIT 0,5
// I need data from this query and rowset count.
// Variable count -- Stores the number of rows returned by first query,
When first query rowset is smaller than 5 rows, then
I make new query from table z
Select * From `z` Limit 0,(5 - count)
--------------------------------
Trick by FOUND_ROWS not working.
--------------------------------
Problems:
How to do it in Store procedure / function (MySQL)?
How get from first query (rowset and number of returned rows) in one query?
--------------------------------
Targets:
After work function should return
Sum of rowset (query 1 and 2).
Or
rowset query 1
I was found solution:
MySQL (Content of Store Procedure):
Set @tmp = 0;
Select `field_1`, `field_2` From `table_1` Where @tmp := @tmp + 1 LIMIT 0 ,5;
// We have row set and in session variable (@tmp) - number of returned rows
@TIP
@tmp := @tmp + 1
It's Must be before all conditions in where.
For example:
[.....] Where @tmp := @tmp + 1 And `field_2` > 1 LIMIT 0, 5;
Will return always 1...
Correct Version
[.....] Where `field_2` > 1 And [Other conditions] And @tmp := @tmp + 1 LIMIT 0, 5;