1

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?

Lars Winkler
  • 37
  • 1
  • 4

1 Answers1

3

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;
Rahul
  • 76,197
  • 13
  • 71
  • 125