我可以直接加入SELECT语句而不使用视图吗?

时间:2010-11-17 13:10:40

标签: mysql join subquery

是否可以在不创建视图的情况下执行以下操作?即通过直接加入这些SELECT?

CREATE VIEW temp_first AS SELECT MIN(DATE) AS mindate,id FROM mytable GROUP BY id
#
SELECT *, t.mindate FROM aggregate_analysis a
JOIN temp_first t
ON t.id = a.id 
WHERE (.... ) 
ORDER BY mindate DESC

1 个答案:

答案 0 :(得分:4)

您应该能够使用子查询/子选择替换选择中的视图参考。

看看

这样的东西
SELECT  *, 
        t.mindate 
FROM    aggregate_analysis a JOIN 
        (
            SELECT  MIN(DATE) AS mindate,
                    id 
            FROM    mytable 
            GROUP BY id
        ) as t  ON t.id = a.id  
WHERE   (.... )  
ORDER BY    mindate DESC