Using IN with tuples in SQL (SQLite3)

I have the following table in a SQLite3 database:

CREATE TABLE overlap_results (
neighbors_of_annotation varchar(20),
other_annotation varchar(20),
set1_size INTEGER,
set2_size INTEGER,
jaccard REAL,
p_value REAL,
bh_corrected_p_value REAL,
PRIMARY KEY (neighbors_of_annotation, other_annotation)
);

I would like to execute the following query:

SELECT * FROM overlap_results WHERE 
(neighbors_of_annotation, other_annotation)
IN (('16070', '8150'), ('16070', '44697'));

That is, I have a couple of tuples of annotation identifiers, and I would like to get entries for each of these tuples. The sqlite3 query gives me the following error:

SQL error: near ",": syntax error

How to correctly express this as an SQL statement?


EDIT I understand that I didn’t explain very well what I really was after. Let me try another crack.

If a person gives me an arbitrary list of terms in neighbors_of_annotationwhich they are interested in, I can write an SQL statement, as shown below:

SELECT * FROM overlap_results WHERE 
neighbors_of_annotation
IN (TERM_1, TERM_2, ..., TERM_N);

, , (TERM_1,1, TERM_1,2), (TERM_2,1, TERM_2,2),..., (TERM_N,1, TERM_N,2), TERM_i,1 neighbors_of_annotation TERM_i,2 other_annotation. SQL ()?

, , , , . AND / OR .

+3
2

SQL. , , . :

SELECT * FROM overlap_results
WHERE neighbors_of_annotation = '16070'
AND   other_annotation = '8150'
UNION ALL SELECT * FROM overlap_results
WHERE neighbors_of_annotation = '16070'
AND   other_annotation = '44697';

, , , , AND ORs:

SELECT * FROM overlap_results
WHERE (neighbors_of_annotation = '16070' AND other_annotation =  '8150')
OR    (neighbors_of_annotation = '16070' AND other_annotation = '44697');

, (, , - ), :

query  = "SELECT * FROM overlap_results"
query += " WHERE (neighbors_of_annotation, other_annotation) IN ("
sep = ""
for element in list:
    query += sep + "('" + element.noa + "','" + element.oa + "')"
    sep = ","
query += ");"

- :

query  = "SELECT * FROM overlap_results "
sep = "WHERE "
for element in list:
    query += sep + "(neighbors_of_annotation = '" + element.noa + "'"
    query += " AND other_annotation = '" + element.oa + "')"
    sep = "OR "
query += ";"
+4

- SQL-, IN. , :

SELECT * FROM overlap_results WHERE (neighbors_of_annotation = '16070' and other_annotation = '8150') or (neighbors_of_annotation = '16070' and other_annotation = '44697')

, :

SELECT * FROM overlap_results WHERE neighbors_of_annotation = '16070' and (other_annotation = '8150' or other_annotation = '44697')

SQL WHERE- .

+2

Source: https://habr.com/ru/post/1740246/


All Articles