SQL ERROR in Syntax when using WITH [duplicate]

大城市里の小女人 提交于 2021-02-17 05:56:20

问题


I want to use a SQL Query with the WITH clause an I get a Syntax Error.

I´m using MySQL Version 5.6.28

Here a simple Code example

WITH alias_test AS (SELECT id, title FROM `tips_locations`)
SELECT id, title
FROM alias_test

Here the error I get in my SQL Tool

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'alias_test AS (SELECT id, title FROM tips_locations) SELECT id, title FROM ali' at line 1

Can you Help me?


回答1:


MySQL doesn't support WITH clause or CTE and thus the error. Alternative, you can either use a temporary table or a normal table like

CREATE TEMPORARY TABLE alias_test AS 
SELECT id, title FROM `tips_locations`;

SELECT id, title
FROM alias_test;


来源:https://stackoverflow.com/questions/42306058/sql-error-in-syntax-when-using-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!