How do you use the “WITH” clause in MySQL?

前端 未结 7 1098
耶瑟儿~
耶瑟儿~ 2020-11-22 04:02

I am converting all my SQL Server queries to MySQL and my queries that have WITH in them are all failing. Here\'s an example:

WITH t1 AS
(
              


        
7条回答
  •  灰色年华
    2020-11-22 04:56

    In Sql the with statement specifies a temporary named result set, known as a common table expression (CTE). It can be used for recursive queries, but in this case, it specifies as subset. If mysql allows for subselectes i would try

    select t1.* 
    from  (
                SELECT  article.*, 
                        userinfo.*, 
                        category.* 
                FROM    question INNER JOIN 
                        userinfo ON userinfo.user_userid=article.article_ownerid INNER JOIN category ON article.article_categoryid=category.catid
                WHERE   article.article_isdeleted = 0
         ) t1
    ORDER BY t1.article_date DESC Limit 1, 3
    

提交回复
热议问题