Member-only story

Select select_ from from_ where where_;

# This can be a valid SQL query

Liu Zuo Lin
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:

  1. select and where can be column names
  2. from 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_ and where_
  • and a couple of values

Conclusion

--

--

Liu Zuo Lin
Liu Zuo Lin

Written by Liu Zuo Lin

SWE @ Meta | [Ebook] 101 Things I Never Knew About Python: https://payhip.com/b/vywcf

Responses (2)