如何通过外键检索列数据 [英] how to retrieve columns data by foreign key

查看:103
本文介绍了如何通过外键检索列数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个表[Test1-Test2]

Test1列:-
Test1Informations
Test1Data
Test1Company
TestID外键
Test1Code
Test1Image

Test2列:-
TestID主键
Test2Image
Test2Data
TestName

我想使用外键检索TestName值

i have 2 tables [Test1 - Test2]

Test1 Columns:-
Test1Informations
Test1Data
Test1Company
TestID Foreign Key
Test1Code
Test1Image

Test2 Columns:-
TestID Primary Key
Test2Image
Test2Data
TestName

i want to retrieve the TestName Value using foreign key

推荐答案

您是否对联接有所疑问?您可以使用外键将两个表连接起来,例如:
Are you wondering about joins? You can join the two tables using the foreign key for example like:
SELECT *
FROM Test1 INNER JOIN Test2
     ON Test1.TestID = Test2.TestID


那将带来所有匹配的行.有关联接的信息,请参见: http://www.w3schools.com/sql/sql_join.asp [ ^ ]


That would bring all the matching rows. For information about joins, see: http://www.w3schools.com/sql/sql_join.asp[^]


< ; pre> SELECT Test1.*,Test2.TestName来自Test1内部联接Test2 ON Test1.TestID外键= Test2.TestID主键WHERE ....
在WHERE之后,您可以设置要搜索的条件,这就是我可以做的,希望对您有所帮助

祝你好运:-)
<pre>SELECT Test1.* , Test2.TestName FROM Test1 INNER JOIN Test2 ON Test1.TestID Foreign Key = Test2.TestID Primary Key WHERE ....</pre>

After WHERE you can put whatever condition you want to search by, this is what I could do and I hope I helped

Good Luck :-)


这篇关于如何通过外键检索列数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆