Hepzibah_G Ответов: 1

Как получить имя, поданное для ключа foregin в SQL?


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.


1 Ответов

Рейтинг:
8

OriginalGriff

Попробуй:

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" и "управление" соответственно.