SQLite can't select SQLite can't select sqlite sqlite

SQLite can't select


A SELECT statement always starts with the word SELECT (or WITH, but not in some databases, nor in a subquery), so your first query:

select * from(1, select random())

is invalid because as you can see the subquery starts with the number 1, not the word SELECT

Your second query:

select * from(select random(), 1)

is valid because in the subquery the query starts with the word SELECT

This query:

select * from(select random(), select random());

is invalid because in the from clause you have to list tables, views, or inline views (what you're attempting to do). An inline view has to be a full query meeting the minimum requirements of a select statement, and that query has to be enclosed (). In your query above you are separating two queries with a comma. That is not how you separate queries, otherwise how would the database differentiate between multiple items in your select list and the start of a new query?

This version:

select * from((select random()),(select random()));

Is correct because you've enclosed each inline view in () and separated each enclosed inline view with a comma. Before you did not enclose them.


The parameters in a FROM or JOIN clause must be either table names or subqueries, the latter must be enclosed in parentheses. When you write:

SELECT * FROM (SELECT RANDOM(), 1)

SELECT RANDOM(), 1 is a valid subquery. But when you write:

SELECT * FROM (1, SELECT RANDOM())

1, SELECT RANDOM() is not a subquery. A subquery must start with SELECT.