Member-only story
Select select_ from from_ where where_;
# This can be a valid SQL query
2 min readMay 7, 2024
This article is the result of a random intrusive thought about SQL:
Can “select select from from where where” be a valid SQL query?
^ of course not — select
from
and where
are reserved SQL keywords
I’ve actually tried this with the small glimmer of hope that:
select
andwhere
can be column namesfrom
can be a table name
But of course this didn’t work (thankfully, or else this could be abused)
The next best alternative
SELECT select_ FROM from_ WHERE where_;
^ So I tried to make this a valid SQL query
CREATE TABLE from_(
select_ INT PRIMARY KEY,
where_ BOOLEAN
);
INSERT INTO from_ VALUES
(1, true), (2, true), (3, true), (4, true);
So with the query, we have:
- a table named
from_
- 2 columns named
select_
andwhere_
- and a couple of values