从tb1到另一个表tb2的2列连接 [英] join of 2columns from tb1 to another table tb2
本文介绍了从tb1到另一个表tb2的2列连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨frnds
我在mysql中有2个表我想从table1中只选择2列并想加入table2我尝试过内连接,左连接除了它不工作之外的所有PLZ帮助
>选择年份,批次从tb1左边加入tb2到tb1;
解决方案
你的在
上是完全错误的。 />
您需要一张桌子上的键
和外键
另一个引用第一个的列。
然后选择变为类似
选择年,从 tb1
left join tb2 on tb1。 key = tb2.foreignkey
有一个关于如何编写MySQL查询的教程at tutorialspoint [ ^ ]
如果你有很多公司要在表之间匹配的列,然后将这些列添加到ON子句。例如
在tb1.key = tb2.foreignkey 和tb1.col2 = tb2.col2和tb1.col3 = tb2.col3 等左连接tb2
hi frnds
I have 2 tables in mysql i want to select only 2 columns from table1 and want to join on table2 i had tried inner join,left join and all but its not working plz help
> select year,batch from tb1 left join tb2 on tb1;
解决方案
Youron
is completely wrong.
You will need akey
on one table and aforeign key
column on the other that refers back to the first one.
The select then becomes something like
select year, batch from tb1 left join tb2 on tb1.key = tb2.foreignkey
There is a tutorial on how to write MySQL queries at tutorialspoint[^]
[Edit]
If you have many columns that you want to match on between the tables then just add those columns to the ON clause. Eg
left join tb2 on tb1.key = tb2.foreignkey and tb1.col2 = tb2.col2 and tb1.col3 = tb2.col3 etc
这篇关于从tb1到另一个表tb2的2列连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文