关于联接表,我不是很有经验,所以这可能是我联接表的结果。我不太明白为什么这个查询重复结果。例如,这应该只返回3个结果,因为对于该特定的作业和修订版,我只有3行,但是返回6,则重复项与前3个完全相同。
SELECT
checklist_component_stock.id,
checklist_component_stock.job_num,
checklist_revision.user_id,
checklist_component_stock.revision,
checklist_category.name as category,
checklist_revision.revision_num as revision_num,
checklist_revision.category as rev_category,
checklist_revision.per_workorder_number as per_wo_num,
checklist_component_stock.wo_num_and_date,
checklist_component_stock.posted_date,
checklist_component_stock.comp_name_and_number,
checklist_component_stock.finish_sizes,
checklist_component_stock.material,
checklist_component_stock.total_num_pieces,
checklist_component_stock.workorder_num_one,
checklist_component_stock.notes_one,
checklist_component_stock.signoff_user_one,
checklist_component_stock.workorder_num_two,
checklist_component_stock.notes_two,
checklist_component_stock.signoff_user_two,
checklist_component_stock.workorder_num_three,
checklist_component_stock.notes_three,
checklist_component_stock.signoff_user_three
FROM checklist_component_stock
LEFT JOIN checklist_category ON checklist_component_stock.category
LEFT JOIN checklist_revision ON checklist_component_stock.revision = checklist_revision.revision_num
WHERE checklist_component_stock.job_num = 1000 AND revision = 1;
表结构:
checklist_category
checklist_revision
checklist_component_stock
最佳答案
线
LEFT JOIN checklist_category ON checklist_component_stock.category
当然应该是这样的
LEFT JOIN checklist_category ON checklist_component_stock.category = checklist_category.category
其他大多数dbms都将报告语法错误,但MySQL将checklist_component_stock.category视为布尔值。对于MySQL,布尔值是一个数字,对于FALSE为0,对于TRUE为!= 0。因此,每个类别!= 0的checklist_component_stock都将连接到checklist_category中的所有记录。
关于mysql - 为什么此查询重复结果?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22864189/