MySQL Multiple Joins in one query?

后端 未结 4 797
执念已碎
执念已碎 2020-12-02 05:45

I have the following query:

SELECT
  dashboard_data.headline,
  dashboard_data.message,
  dashboard_messages.image_id 
FROM dashboard_data
INNER JOIN dashboa         


        
4条回答
  •  日久生厌
    2020-12-02 06:34

    I shared my experience of using two LEFT JOINS in a single SQL query.

    I have 3 tables:

    Table 1) Patient consists columns PatientID, PatientName

    Table 2) Appointment consists columns AppointmentID, AppointmentDateTime, PatientID, DoctorID

    Table 3) Doctor consists columns DoctorID, DoctorName


    Query:

    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
    

    I wrote the solution to get date format like "mm/dd/yy" (under my name "VARUN TEJ REDDY")

提交回复
热议问题