IN
clause is a boolean predicate, so you'll need to replace it with a dummy recordset:
SELECT m.*
FROM (
SELECT 1 AS id
UNION ALL
SELECT 2 AS id
UNION ALL
SELECT 3 AS id
UNION ALL
SELECT 666 AS id
) q
LEFT JOIN
mytable m
ON m.id = q.id
In SQL Server 2008
, you can run this query:
SELECT *
FROM @mydata d
LEFT JOIN
mytable t
ON t.id = d.id
with @mydate
is a table variable, passed as a parameter from the client.
In PostgreSQL
, you can run this query:
SELECT *
FROM (
SELECT :arr[s] AS id
FROM generate_series(1, array_upper(:arr, 1)) s
) q
LEFT JOIN
mytable t
ON t.id = q.id
where :arr
is an array [1, 2, 3, 666]
, also passed from the client as the parameter.
In Oracle
, you can do:
SELECT *
FROM TABLE(:mycol) q
LEFT JOIN
mytable t
ON t.id = q.id
, where :mycol
is a variable of collection type, passed from the client.