mercredi 30 juin 2021

why Mysql Rand() has a different behaviour while using left join

I'm trying to implement some fuzziness thing in a mysql (v5.7 on Mac & Linux) query but realized mysql Rand() has a weird behaviour while using/not using a left join with an empty table!

To reproduce this I made 2 tables, t1 with 1000 records and t2 with no record.
Then I tried to run these 2 queries:

SELECT count(*) FROM t1 LEFT JOIN t2 ON t1.id = t2.id WHERE RAND() < 0.5;
SELECT count(*) FROM t1 WHERE RAND() < 0.5;

The first query returns ~250 records but the second one returns ~500.

Couldn't find any explanation about this.
Any idea would be helpful




Aucun commentaire:

Enregistrer un commentaire