Mysql
 sql >> Database >  >> RDS >> Mysql

Come selezionare i dati da più tabelle utilizzando correttamente join/sottoquery? (PHP-MySQL)

Prova qualcosa del genere (non l'ho testato, puoi provarlo):

SELECT
  projectdetails.ProjectDetailsID,
  projectheader.ProjectID,
  projectheader.ProjectName,
  projectheader.Lead,
  projectheader.StartDate,
  projectheader.EndDate,
  projectheader.Status,
  projectheader.Remarks,
  projectdetails.EmployeeID,
  employee.Firstname,
  employee.Lastname,
  CONCAT(Lead.Firstname,' ',Lead.Lastname) AS Leadname
FROM
  projectheader,
  projectdetails,
  employee,
  employee as Lead
WHERE projectheader.ProjectID = projectdetails.ProjectID
AND projectdetails.EmployeeID = employee.EmployeeID
AND projectheader.Lead = Lead.EmployeeID