For a given list of primary keys (with a single id column as primary key), I want to retrieve the rows pertaining to those ids in order from the database. If the id doesn't exist in the database, then that specific row should be all nulls.
I have two such lists of equal length, for two different tables in the database. I want to do a side-by-side join of the two tables (on the server side if possible).
We have two id lists: [1, 2, 3, 4]
and [3, 2, 4, 1]
.
Query using first list on first table retrieves:
id c1
---- ----
1 a
2 b
3 c
4 d
Query using second list on second table retrieves:
id c2
---- ----
3 g
2 h
4 i
1 j
Final result should be:
c1 c2
---- ----
a g
b h
c i
d j