Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Oracle to MySQL Simple Query Coversion SELECT a + b AS total FROM (SELECT 1 AS a, 2 AS b FROM DUAL)

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading