Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Left Join (Between Condition)

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
like image 705
ELM Avatar asked Dec 21 '22 08:12

ELM


1 Answers

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
like image 180
Ken Bloom Avatar answered Jan 14 '23 08:01

Ken Bloom