MySQL 在不使用连接的情况下从两个不同的表中选择数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17430755/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selecting data from two different tables without using joins
提问by Norman
I've got table1
and table2
and need to get data out from each of them.
我有table1
和table2
,并需要从他们每个人获取数据了。
Table1
表格1
"id" "name" "description"
"1" "Windows" "Microsoft Windows 8"
Table2
表2
"id" "type" "name" "description"
"1" "22" "Microsoft Windows" "Microsoft Windows 8 Home"
"2" "2" "Not an Edit" "Not an Edit"
I do the select like this
我做这样的选择
select table1.name, table1.description,
table2.name, table2.description
from table1,table2
where table2.id=table1.id and table2.`type`=22;
Will using an inner join be quicker or more efficient when selecting some 500+ rows at a time?
一次选择大约 500 多行时,使用内部联接会更快或更有效吗?
I've seen most examples using a inner join to do this.
我见过大多数使用内部联接来执行此操作的示例。
回答by Tamim Al Manaseer
No difference, just a syntax difference, internally they yield the same execution plan:
没有区别,只是语法不同,在内部它们产生相同的执行计划:
回答by Jitendra Parmar
This is the correct answer without join
这是没有加入的正确答案
select t1.*,t2.* from t1,t2 where t1.id=t2.id;
回答by Amit Singh
You can do like this..
你可以这样做..
select table1.name, table1.description,
table2.name, table2.description
from table1 inner join Table2 on table2.id=table1.id and table2.`type`=22