0

我最近添加了一个排序字段,现在我想对结果进行排序。我可以用 PHP 或直接在数据库上做。所以我尝试了第二个:

SELECT *
FROM constructions
AS whole
INNER JOIN
(
    SELECT DISTINCT construction
    FROM data
    AS results
    WHERE product =2
    AND application =1
    AND requirement =1
)
ON whole.id = results
ORDER BY whole.sorting

我尝试使用内部连接将完整的表与结果集匹配。但我无法让它工作(#1248 - Every derived table must have its own alias)。我尝试使用别名,但仍然有问题。也许我不应该使用内部联接IN()来代替使用。

4

2 回答 2

3

2个明显的语法错误:

SELECT *
FROM constructions
AS whole
INNER JOIN
(
    SELECT DISTINCT construction AS results
    FROM data
    WHERE product =2
    AND application =1
    AND requirement =1
) AS a
ON whole.id = a.results
ORDER BY whole.sorting
于 2012-04-17T09:27:19.667 回答
1

尝试获取这样的数据...

 SELECT *
    FROM constructions
    where 
    construction
    in
    (
        SELECT DISTINCT construction
        FROM data
        AS results
        WHERE product =2
        AND application =1
        AND requirement =1
    )
于 2012-04-17T09:27:28.757 回答