Sqlite IN clause 小常識

Ensky Lin
Ensky Lin
Apr 21 · 2 min read
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

Ensky Lin

Written by

Ensky Lin

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade