开发者

How to extract random entries from multiple mysql tables directly from database?

开发者 https://www.devze.com 2023-01-05 20:01 出处:网络
I am trying to extract a maximum of 5 ent开发者_StackOverflowries randomly from two tables combined directly from database.

I am trying to extract a maximum of 5 ent开发者_StackOverflowries randomly from two tables combined directly from database.

kinda like this SELECT RANDOM FROM table1,table2 LIMIT 0,5)

I am aware that I can filter the result later on from PHP, but I want only 5 random rows from database.

These multiple tables might have different database structure


Have you considered something like

(SELECT * from table1) union (select * from table2) order by rand() limit 0,5
0

精彩评论

暂无评论...
验证码 换一张
取 消