I have two tables that I can perfectly query seperately.
table1 stores ranges:
SELECT range_id, range_from, range_to FROM table1;
table2 stores IDs:
SELECT MAX(id) FROM table2 WHERE id BETWEEN <x> AND <y>;
I need a query that for each tuple (range_id, from, to) from table1 selects the MAX(id) from table2 such that MAX(id) is between from and to:
range_id max(id)
-------- -------
foo 3
bar 17
snafu 823467
I don’t see how to accomplish this, since there’s nothing to JOIN here.
Any ideas?
1 Answer