![](/img/trans.png)
[英]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.