gpt4 book ai didi

mysql - 查询连接多个表

转载 作者:搜寻专家 更新时间:2023-10-30 23:39:14 25 4
gpt4 key购买 nike

我刚开始使用 sql 数据库 我有一个关于将从多个表返回结果的查询的问题。抱歉,如果这真的很微不足道,我一直在尝试自己研究它,但不知道要查找的适当术语。

我有三个表:

Patient -
PatientID*
Surname
FName
DoB
Address
PhoneNo

Doctor -
DoctorID*
Surname
FName
DoB
Address
PhoneNo

Appointment -
AppointmentID*
DoctorID
PatientID
Time
Date

我希望查询返回所有预约,但将 DoctorID 和 PatientID 替换为匹配的医生姓氏和患者姓氏。因此返回 AppointmentID、医生姓氏、患者姓氏、时间和日期。

我希望我已经很好地解释了这一点,以便有人能够理解!

在此先感谢您的帮助!

最佳答案

应该是内连接

select a.AppointmentID, b.Surname, b.FNAME, c.Surname, c.FName
from Appointment as a
Inner join Doctor as b on b.DoctorID = a.DoctorID
Inner join Patient as c on c.PatientID = a,PatientID

关于mysql - 查询连接多个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37164827/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com