Home > Software design >  Oracle to MySQL Simple Query Coversion SELECT a b AS total FROM (SELECT 1 AS a, 2 AS b FROM DUAL)
Oracle to MySQL Simple Query Coversion SELECT a b AS total FROM (SELECT 1 AS a, 2 AS b FROM DUAL)

Time:07-06

I have a simple Oracle Query

SELECT a   b AS total FROM (SELECT 1 AS a, 2 AS b FROM DUAL)

I will use MySQL this time so I tried doing this:

SELECT a   b AS total FROM (SELECT 1 AS a, 2 AS b)

But it's giving me error

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

CodePudding user response:

Every subquery or derived table requires an alias in MySQL (as well as most flavors of SQL), so use this version:

SELECT a   b AS total
FROM
(
    SELECT 1 AS a, 2 AS b
) t;   -- change is here

Note also that I removed the FROM dual clause in the subquery. In MySQL, constants can be selected without using the dual table (unlike in Oracle, where it is necessary).

  • Related