0

我有三个名为 edum_application、edua_courseEvent 和 edua_coursePackage 的表。

我正在写一个问题以从 edum_application 获取所有应用程序,其中所有 courseEvent 的 coursePackage_id 都是 x 并且都具有相同的 applicationWrapper_id

这个查询有效,但它有效吗?

SELECT app.application_id, app.applicationWrapper_id
FROM edum_application AS app
    INNER JOIN edua_courseEvent AS ce ON app.courseEvent_id = ce.courseEvent_id
WHERE app.applicationWrapper_id = 662
    AND app.courseEvent_id IN
    (
        -- Is this really efficient?
        SELECT ce.courseEvent_id
        FROM edua_courseEvent AS ce
        WHERE ce.coursePackage_id =
        (
            SELECT coursePackage_id
            FROM edua_courseEvent AS ce
            WHERE ce.courseEvent_id = 13377
        )
    )

输出:

application_id  applicationWrapper_id
72643           662
72645           662
72646           662
72647           662
4

1 回答 1

1

试试这个:

SELECT     app.application_id, app.applicationWrapper_id
FROM       edum_application AS app
INNER JOIN edua_courseEvent AS ce
ON         app.courseEvent_id = ce.courseEvent_id
INNER JOIN edua_courseEvent AS ce2
ON         ce.coursePackage_id = ce2.coursePackage_id
WHERE      app.applicationWrapper_id = 662
AND        ce2.courseEvent_id = 13377

您可能需要一个 DISTINCT,具体取决于不同表之间/关系中的行数。

于 2012-06-27T07:11:01.243 回答