SQL Left Join (Between Condition)

ELM picture ELM · Sep 19, 2011 · Viewed 7.7k times · Source

Is it possible to use a BETWEEN statement as a condition for a LEFT JOIN?

SELECT Table_1.*, Table_2.*
FROM Table_1 LEFT JOIN Table_2
ON Table_1.value BETWEEN Table_2.Value_1 AND Table_2.Value_2

Answer

Ken Bloom picture Ken Bloom · Sep 19, 2011

Yes, it is, but you need to specify a column name from Table_1, like so:

SELECT Table_1.*, Table_2.*
FROM Table_1 LEFT JOIN Table_2
ON Table_1.Value BETWEEN Table_2.Value_1 AND Table_2.Value_2