Left joins where there is an OR clause

68 views Asked by At

Consider the following Query in RQB using Foreign Keys

I have two tables, companies and weather.

The foreign key joins the weather to company on zip code

The RQB I am entering is:

Employees Total - Greater Than - 1000

OR

FK Weather.Temp < 50

The SQL that is generated by RQB is (approximately):

SELECT * FROM companies
INNER JOIN weather
ON companies.zip = weather.zip
WHERE company.employees > 1000
OR
weather.temp < 50

The issue is that from the UI perspective if I specify an OR and use a foreign key in the OR WHERE clause, I should get a LEFT JOIN instead of an INNER JOIN. I would expect the INNER JOIN in the case of an AND, but an OR requires a LEFT JOIN so I get all the companies with Employees > 1000 and I also get all of the company records with a match of the company records where Temp was < 50

My question is, is there a way to get RQB to output a LEFT JOIN on a foreign key where the referenced table is used with an OR?

1

There are 1 answers

3
salk31 On

Not with the current code I'm afraid. Best to raise an issue?

Could start to get tricky as that join could go on to be used by other things? Although nulls should resolve to false.