我正在尝试更好地学习 MySQL 选择语句,但我最终以某种方式选择了具有相同值的多行。如果我删除最后一个 JOIN,查询会正确显示,但我仍然需要将 tasks.Rate_Schedule_ID 与 hourlyrates.Rate_Schedule_ID 连接起来,如最后一个 JOIN 语句所示。
编辑:每行复制一次。这是我得到的结果的图片。
SELECT
project_timecard_tasks.Task_ID,
project_timecard_tasks.DateTime,
project_timecard_tasks.Total_Hours,
project_timecard_tasks.User_ID,
project_timecard_tasks.Project_ID,
users.User_ID,users.FirstName,
users.LastName,
tasks.id,
tasks.taskName,
tasks.billingOption,
tasks.fixedRate,
tasks.Rate_Schedule_ID,
hourlyrates.Rate_Schedule_ID,
hourlyrates.hourlyRate
FROM
project_timecard_tasks
JOIN users ON project_timecard_tasks.User_ID = users.User_ID
JOIN tasks ON project_timecard_tasks.Task_ID = tasks.id
JOIN hourlyrates ON tasks.Rate_Schedule_ID = hourlyrates.Rate_Schedule_ID
WHERE
project_timecard_tasks.Project_ID = '$jobNumber'