Toni Ivanov
Toni Ivanov

Reputation: 81

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:

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

Upvotes: 1

Views: 272

Answers (1)

Zakaria
Zakaria

Reputation: 4806

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;

Upvotes: 3

Related Questions