Tek bir SQL sorgusunda iki LEFT JOINS kullanma deneyimimi paylaştım.
3 masam var:
Tablo 1) Hasta, Hasta Kimliği, Hasta Adı sütunlarından oluşur
Tablo 2) Randevu, Randevu Kimliği, RandevuTarihSaati, Hasta Kimliği, Doktor Kimliği sütunlarından oluşur
Tablo 3) Doktor, DoctorID, DoctorName sütunlarından oluşur
Sorgu:
SELECT Patient.patientname, AppointmentDateTime, Doctor.doctorname
FROM Appointment
LEFT JOIN Doctor ON Appointment.doctorid = Doctor.doctorId //have doctorId column common
LEFT JOIN Patient ON Appointment.PatientId = Patient.PatientId //have patientid column common
WHERE Doctor.Doctorname LIKE 'varun%' // setting doctor name by using LIKE
AND Appointment.AppointmentDateTime BETWEEN '1/16/2001' AND '9/9/2014' //comparison b/w dates
ORDER BY AppointmentDateTime ASC; // getting data as ascending order
"Aa / gg / yy" gibi bir tarih formatı almak için çözüm yazdım ("VARUN TEJ REDDY" adımın altında)