从外键关系获取名称

huangapple go评论47阅读模式
英文:

Obtain names from foreign key relationship

问题

我想要修改我的查询结果,以便给我不同的结果,例如

当我运行这个查询

select *
from receipt
where receiptId = 358914592

它给我一个表格,像这样

receiptId date price salesRep PatientId stat reqDoc reviewwee patho medtech
358914592 2023-06-21 1200 NULL 1023957457 done dr. Dave 10111012317 64242 32347

我想要查询显示病理医师、审核人员和医疗技师的姓名,而不是它们的主键

像这样

receiptId date price salesRep PatientId stat reqDoc reviewwee patho medtech
358914592 2023-06-21 1200 NULL 1023957457 done dr. Dave nurse Joy Dr. Hawk browns michaela jose
英文:

I would like to alter my query result to give me a different result for example

when I run this query

select *
from receipt
where receiptId = 358914592`

It gives me a table like this

receiptId date price salesRep PatientId stat reqDoc reviewwee patho medtech
358914592 2023-06-21 1200 NULL 1023957457 done dr. Dave 10111012317 64242 32347

I want the query to show the names of the pathologist, reviewee and medtech rather than their primary keys

like this

receiptId date price salesRep PatientId stat reqDoc reviewwee patho medtech
358914592 2023-06-21 1200 NULL 1023957457 done dr. Dave nurse Joy Dr. Hawk browns michaela jose

答案1

得分: -1

需要使用连接操作才能显示该信息。

select receiptId, date, price, patient,..., path.name...
from receipt as rec
join pathologist as path on rec.pathId = path.Ud
where receiptId = 358914592
英文:

You need to use Joins in order to display that information.

select receiptId, date, price, patient,..., path.name...
from receipt as rec
join pathologist as path on rec.pathId = path.Ud
where receiptId = 358914592`

huangapple
  • 本文由 发表于 2023年6月29日 15:58:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76579094.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定