[英]How to display results from two different tables with the same column names
[英]How to get the results from two tables for the same column values?
请提供有关如何从两个具有匹配列值的表中获取值的解决方案,而不是具有前键ID的解决方案。
EX:
Tablea
Employee name DEP Grade
Hari Science A
ram Maths B
Tableb
Employee name other Fee Tuition
Hari 1000 200
ram 3000 100
预期结果:
Employee name other Fee Tuition DEP GRADE
Hari 1000 200 science a
ram 3000 100 Maths b
两个表都没有外键关系。 只有列值(hari,ram)与两个表都匹配。
您不需要外键即可执行联接,只需匹配值即可:
SELECT a.name, other_fee, tuition, dep, grade
FROM a
JOIN b ON a.name = b.name
您可以尝试使用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.