Quick question. feel like a noob but haven’t found the right syntax for this yet.
Have 3 tables.
T1-
AsessessmentID(auto Incr)
inspectorID,
assistantID,
plant name
T2-
UserID(auto Incr),
username,
name
T3-
plantID(auto Incr)
PlantName
Basically I want to have a php/mysql table that is very similar to T1 but instead of listing the ID’s I would like the names. Heres my call so far:
SELECT DISTINCT a.AssessmentID, u.Name, a.PlantAssistID, p.PlantName
FROM assessmentscores AS a, user AS u, plant AS p
WHERE u.userID=a.InspectorID AND u.Name='$name' AND p.PlantID=a.Plant
This works as u.Name will give me the name for the inspector but I can’t figure out how to call the second (a.PlantAssistID). Just keep getting the same name for both.
What call to the server should I use to return two different names. Any help would be appreciated
First things first: if you want to select from the assessment table and augment the resultset using the other tables, think about using
LEFT JOIN. If you want a more restrictive result, where only assessments are returned that are actually associated with existing users, use anINNER JOINinstead. The example below usesLEFT JOIN.Not sure whether this is what you want exactly, but you can try:
Result: