Reputation: 141
I have little experience using SQL, and I am now using JDBC to connect to my database. I am using sqlite, my schema looks as follows:
id1, id2, value1, value2
I want to extract rows based on a list of given pairs of id1 and id2. I know Postgresql can do
SELECT *
FROM table
WHERE ("id1", "id2") IN (('1', '2'), ('3', '4'));
But what about sqlite?
Upvotes: 1
Views: 81
Reputation: 28403
Instead of IN
, you could use a JOIN
using the two fields:
SELECT U.*
FROM Table U
INNER JOIN Table1 UT
ON U.id1 = UT.id1
AND U.id2 = UT.id2
Upvotes: -1
Reputation: 180020
Since version 3.15.0, SQLite supports row values:
SELECT *
FROM MyTable
WHERE (id1, id2) IN (VALUES ('1', '2'), ('3', '4'));
Upvotes: 0
Reputation: 7377
if you have a long list you can do this
SELECT *
FROM table
WHERE (id1 in('1','11','111') and id2 in ('22','2','222')) OR
(id1 in('333','33','3') and id2 in('444,'44','4')')
Upvotes: 0
Reputation: 31239
You could do something like this:
SELECT *
FROM table
WHERE (id1 = '1' AND id2= '2') OR (id1='3' AND id2='4');
Upvotes: 1
Reputation: 35154
You could use an OR
-condition:
SELECT *
FROM table
WHERE (id1='1' and id2='2') OR
(id1='3' and id2='4')
Upvotes: 1