1

我正在尝试执行以下 MySql 查询,当我运行它时,它告诉我子查询中的“q.object_id”是未知的(如果我将其更改为 o.id,它表示相同)。

SELECT q.*, (SELECT c.title 
             FROM api_course c 
             LEFT OUTER JOIN api_object_parents op 
                 ON c.object_id = op.parent 
                     AND op.object_id = q.object_id) as parent_title
    FROM api_quiz q
    LEFT OUTER JOIN api_object o ON q.object_id = o.id
    WHERE o.type = 'Quiz'

基本上我需要获得在主查询中使用的相同 id 并在子查询中使用它。

谢谢!

4

1 回答 1

4

这是你想要的?

SELECT  a.*, d.title
FROM    api_quiz a
            LEFT JOIN   api_object b
                on a.object_id = b.id
            LEFT JOIN   api_object_parents c
                ON c.parent = a.object_id
            LEFT JOIN   api_course d 
                ON c.object_id = c.parent
于 2012-08-21T04:12:08.047 回答