I have two tables, table 1 has one row per variable, while table 2 has many rows per variable. I want to randomly select 1000 rows from table 1 (1000 variables) and then join those to table 2. Final table will have many rows per variable. I’m also adding conditions for the selection from both tables. This is my code but it’s not picking 1000 variables from table 1:
SELECT t1.var1, t1.var2, t2.var3, t2.var4
FROM table1 t1
RIGHT JOIN (SELECT var1, var3 FROM table2 ORDER BY RAND() LIMIT 1000) t2
ON t1.var1 = t2.var2
WHERE t1.var2 < 90 AND t2.var4 = "asd";
What am I missing?