本文介绍了如何在SQL中获取foregin密钥的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi am new to sql db.i have one table say MyTable here am saving(Id, Dcotor name,Department) as column where Id is primay key .DoctorName and Department are foregin key.
so when in call the MyTable its displaying me like this when binding to grid view.
Id doctorName Department
1 1 1
2 4 3
here doctor name and Department showing its Corrsponding ids.
But i want its coresponding names from their Table.
help me frinds..
What I have tried:
i dontknow to start...
<pre><pre>hi am new to sql db.i have one table say MyTable here am saving(Id, Dcotor name,Department) as column where Id is primay key .DoctorName and Department are foregin key.
推荐答案
SELECT a.ID, doc.Name, dep.Name FROM MyTable a
JOIN Doctors doc ON a.[Doctor Name] = doc.ID
JOIN Departments dep ON a.Department = dep.ID
但是重命名你的列:DocID和DepID分别比DoctorName和Department准确得多。
But rename your columns: "DocID" and "DepID" are much more accurate than "DoctorName" and "Department" respectively.
这篇关于如何在SQL中获取foregin密钥的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!