0

While I am trying to select a table on a MySQL data base, I am getting the following error:

SQL Error [1064] [42000]: 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 'table_1 as (

    SELECT
        user_id,
        age
    FROM example_table

)

S' at line 3

Error position: line: 2

Below I included the query:

WITH

table_1 as (

    SELECT
        user_id,
        age
    FROM example_table

)

SELECT * FROM table_1;

I checked different contributions on StackOverflow and other sites (like ERROR 1064 (42000) and Fix ERROR 1064 (42000) while creating a database in MySQL? ). I am aware there is some syntax error but I am not able to find a solution.

Help is really appreciated

Albin
  • 822
  • 1
  • 7
  • 25
  • 1
    Does this answer your question? [Syntax error due to using a reserved word as a table or column name in MySQL](https://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – David May 13 '22 at 11:42
  • 1
    You can safely assume that `table` is a reserved keyword in probably every RDBMS. – David May 13 '22 at 11:42
  • @David, I find no exceptions at https://en.wikipedia.org/wiki/SQL_reserved_words. – jarlh May 13 '22 at 11:48
  • @David there is also an error with another naming than table – Albin May 13 '22 at 11:56
  • @Albin: Is it the exact same error, in the exact same place? "There is also an error" isn't very specific. Perhaps you could update the question? – David May 13 '22 at 11:56
  • @David I'm sorry - yes, it is the same error. I also edited the question by replacing table with table_1 – Albin May 13 '22 at 11:59
  • 3
    Probably you are using an older `MySQL` version which does not support `WITH` clause. https://dbfiddle.uk/?rdbms=mysql_8.0&rdbms2=mysql_5.7&fiddle=ac12e0cb53ebf5bb90977801ecebf3dc – Ergest Basha May 13 '22 at 12:10
  • @Ergest Basha thanks a lot! That is actually the cause of the error – Albin May 13 '22 at 12:48

0 Answers0