Sqlite IN clause 小常識

SELECT * FROM some_table         --- A
WHERE some_column IN ((
SELECT * FROM another_table --- B
));
expr 中的 IN 的部份
sqlite> CREATE TABLE temp (
...> id integer
...> );
sqlite> INSERT INTO temp VALUES(1),(2),(3);
sqlite> SELECT * FROM temp WHERE id IN (1,2,3);
id = 1
id = 2
id = 3
sqlite> SELECT * FROM temp WHERE id IN (SELECT id FROM temp);
id = 1
id = 2
id = 3
sqlite> SELECT * FROM temp WHERE id IN ((SELECT id FROM temp));
id = 1
sqlite> SELECT * FROM temp WHERE id IN ((SELECT id FROM temp), (SELECT 2 FROM temp));
id = 1
id = 2

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Ensky Lin

Ensky Lin

More from Medium

6 Major Differences Between SQL Server DELETE and TRUNCATE options.

Data Types

Harry Potter and the relational database management system.

Reference: Types of SQL Joins