My Procedure: (It’s a scheme)
delimiter //
CREATE PROCEDURE get_random_data()
BEGIN
Declare Count_a INT;
SELECT Floor(Count(`id_x`) * Rand()) INTO Count_a From `x_data` Where `ok_w` = 1 And `active` = 2 And `time` >= Unix_timestamp();
# Now We select Some Rows
SELECT `id_x` From `x_data` Where `spec` = 1 Limit Count_a,3;
# And if Count of this select is small than < 3
IF(row_count() < 3) then
SELECT `id_anonsu` From `x_data` Where `spec` = 0 Limit Count_a,2;
END IF ;
END//
delimiter ;
// Target
How to get the results From BOTH queries?
// One from query before if statement
// Second from query in statement, if first query count is smaller than 3
Ok, I found the answer.
The original code:
Was replaced for:
Better Version:
Work Good with query (Who use LIMIT)
And we need know number of returned rows by (Query)in Store Procedure
Version with show count
Output like this:
Version with hidden count
Output like this:
@TIP
It’s Must be before all conditions in where.
For example:
Will return always 1…
Correct Version