[英]How to get the results from two tables for the same column values?
Please provide the solution for how to get the values from two table with matching column values,Not with foreiegn key id. 请提供有关如何从两个具有匹配列值的表中获取值的解决方案,而不是具有前键ID的解决方案。
EX: EX:
Tablea
Employee name DEP Grade
Hari Science A
ram Maths B
Tableb
Employee name other Fee Tuition
Hari 1000 200
ram 3000 100
Expected result: 预期结果:
Employee name other Fee Tuition DEP GRADE
Hari 1000 200 science a
ram 3000 100 Maths b
There is no foreign key relationship with both the tables. 两个表都没有外键关系。 Only the column values(hari,ram) are matching with both the tables.
只有列值(hari,ram)与两个表都匹配。
You don't need a foreign key in order to perform a join, just matching values: 您不需要外键即可执行联接,只需匹配值即可:
SELECT a.name, other_fee, tuition, dep, grade
FROM a
JOIN b ON a.name = b.name
You can try with join to fetch the data 您可以尝试使用join来获取数据
SELECT b.name, b.other_fee, b.tuition, a.dep, a.grade
FROM b
LEFT JOIN a ON b.name = a.name
使用以下SQL。
select a.[Employee name],[other Fee],[Tuition],[DEP],[GRADE] from Tablea a join tableb b on a.[Employee name]=b.[Employee name]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.