简体   繁体   English

mysql:为查询创建常规表而不是临时表是一种好习惯吗?

[英]mysql: Is it a good practice to create a regular table instead of a temporary table for a query?

I need to put all the result of a query to a temporary table then select from it, but due to the nature of the temporary table, I cannot refer to it more than once in the same query. 我需要将查询的所有结果放到临时表中,然后从中选择,但是由于临时表的性质,我不能在同一查询中多次引用它。 So is it ok to create a uniquely named (regular) table for this and drop it after the query is completed? 那么可以为此创建一个唯一的名称(常规)表并将其在查询完成后删除吗? Or is there a better way to do this? 还是有更好的方法来做到这一点?

I tried using Derived tables but I cannot access it from different blocks. 我尝试使用派生表,但无法从不同的块访问它。

It's not necessarily a matter of whether it's good practice or not. 不一定是好的做法。 Whether it's a regular table, temporary table or derived table they all serve a purpose when trying to accomplish a task. 无论是常规表,临时表还是派生表,它们都可以在完成任务时发挥作用。 Therefore, creating a regular table or a temporary table all depends on you and what you want your application to accomplish at the end of the day. 因此,创建常规表或临时表都取决于您以及您的应用程序最终要完成的工作。

But based on your problem it seems that you might need to create a regular table in this situation since you require access to the table more than once, and you can drop the table after you're finished with it. 但是根据您的问题,在这种情况下您似乎需要创建一个常规表,因为您需要多次访问该表,并且可以在完成该表后将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM