MySQL 中的视图或子查询
用户(用户名,Catogory_ID
,Sub_Category_ID
)
类别(Catogory_ID< /code>,Categories_Name)
SubCatogoies(Sub_Category_ID
,SubCatogoies_Name)
在code
是 FK 及其 PK
问题 1
我需要的是使用所有这三个表创建一个视图OR子查询来获取类别和Sub_Catogory名称作为其ID的
问题2
在exec中什么会更快?
Users(username,Catogory_ID
,Sub_Catergory_ID
)
Categories (Catogory_ID
,Categories_Name)
SubCatogoies(Sub_Catergory_ID
,SubCatogoies_Name)
In code
are FK's and its PK's
Question 1
What i required is to create a view using all these three tables OR a sub query to get the Catogory and Sub_Catogory names as its ID's
Question 2
In exec what will be more faster ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将所有 3 个表中的数据汇总在一起的单个查询看起来像这样:
这可以制作成视图或简单地按原样运行。至于性能,物化视图可能比每次执行时执行连接的即席查询执行得更快。但除非您发现性能问题,否则我不会尝试按照这些方式进行优化。如果即席查询足够快,则不必担心优化它。
A single query that pulls together data from all 3 tables would look something like this:
This could be made into a view or simply run as is. As for performance, a materialized view might perform faster than the ad hoc query performing the joins upon each execution. But I wouldn't try to optimize along those lines unless you're seeing a performance problem. If the ad hoc query is fast enough, don't worry about optimizing it.