0

我目前有:

SELECT * FROM submissions AS s
    LEFT JOIN submission_category AS sc ON s.submission_category = sc.sub_cat_id    
    JOIN hospitals      AS h  ON h.hospital_id        = sc.main_hospital_id
    JOIN products       AS p  ON p.product_id         = s.product_id
    JOIN product_group  AS pg ON pg.id                = p.product_group_id 
    JOIN progress_steps AS ps ON sc.approval_step     = ps.step_id
    WHERE s.approval_status='2' 
    AND sc.user_id='$mask5'

问题是 sc 有 3 行而 s 有 6 行。我需要返回所有六行,但目前它只返回 3,每个 from s 对应于 sc。

根据我现在正在尝试的建议:

SELECT * FROM submissions AS s
LEFT JOIN submission_category AS sc ON (s.submission_category = sc.sub_cat_id AND sc.user_id='$mask5' ) 
JOIN hospitals      AS h  ON h.hospital_id        = sc.main_hospital_id
JOIN products       AS p  ON p.product_id         = s.product_id
JOIN product_group  AS pg ON pg.id                = p.product_group_id 
JOIN progress_steps AS ps ON sc.approval_step     = ps.step_id
WHERE s.approval_status='2'

但仍然得到三排,而不是六排?

4

1 回答 1

0

LEFT JOIN将ed table[s] 的列“转换WHERELEFT JOININNER(sc.user_id = '$mask5' 总是返回NULL或 false,以防 submit_category 中没有相应的行)。进入sc.user_id=...加入条件:

....
LEFT JOIN submission_category AS sc ON (s.submission_category = sc.sub_cat_id AND 
 sc.user_id='$mask5' )
...
于 2013-01-19T05:05:58.670 回答