MYSQL 从所有数据库中选择tableX
假设我有 50 个数据库,它们都具有相同的架构,并且都有表“plays”。
有没有可能的方法可以同时从所有数据库中的表“plays”中选择所有数据?
如果我不知道我有多少个数据库,有什么办法可以做到这一点?
目前我会这样做:
(SELECT * FROM db1.plays WHERE condition)
UNION
(SELECT * FROM db2.plays WHERE condition)
UNION...
(SELECT * FROM db50.plays WHERE condition)
有什么方法可以为此编写更少的代码吗?
问候
Let's say I have 50 databases that all have same schema and all have table 'plays'.
Is there any possible way to SELECT all the data from table 'plays' from all the databases at once ?
Is there any way to do this if I dont know how many databases I have ?
Currently I would do this :
(SELECT * FROM db1.plays WHERE condition)
UNION
(SELECT * FROM db2.plays WHERE condition)
UNION...
(SELECT * FROM db50.plays WHERE condition)
Is there any way to write less code for this ?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定,但是为了缩短代码,您可以执行
Select * FROM db1.plays, db2.plays, ...., db3.plays WHERE
另一件事需要注意的是使用表INFORMATION_SCHEMA。也许其他人有更好的主意。
I'm not sure, but to shorten your code, you could do
Select * FROM db1.plays, db2.plays, ...., db3.plays WHERE <condition>
Another thing that comes to mind is using the table INFORMATION_SCHEMA. Maybe someone else has a better idea.