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

SQL – Problem with subquery in the FROM clause

I am currently learning SQL and I tried testing something but it does not work.

The query that I tried is the following:

SELECT acc_id 
FROM 
(
    SELECT *
    FROM company 
);

The inner query must return the whole table and the outter query must select from that table only a specific column. Simple as it seems this produces an error. The error message is:

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

"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 6" (line 6 being the last line).

I can’t figure out whats the issue.

>Solution :

You need to give an alias to your subquery:

SELECT acc_id 
FROM 
(
    SELECT *
    FROM company 
) AS some_alias;

Although your query can be simplified into:

SELECT acc_id
FROM company;
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