Answer the question
In order to leave comments, you need to log in
SQL query with id selection from list?
Hello.
MySQL database.
There is a table like:
CREATE TABLE `test` (
`id` INT(11) NULL DEFAULT NULL,
`value` INT(11) NULL DEFAULT NULL
)
id | value
------------------------------------
1 10
2 15
3 23
SELECT SUM(value) FROM test WHERE id IN (1, 1, 2);
Answer the question
In order to leave comments, you need to log in
as an option ... collect 1,1,2 in
and join
select sum(value)
from test t
, (select 1 id union all select 1 id union all select 2 id) tab
where t.id = tab.id
Taking into account Update 2 - imho the most correct decision is to select value from base where in and to summarize in .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question