Your statement has multiple problems. First, you should learn and use proper join
syntax and realize that table aliases will simplify the query. That will show that you have no join condition for site_file_sets
, which this is showing as a cross join
.
SELECT sl.*, sfs.*, ds.identifier, ds.date_due
FROM surplusland_list sl join
demandstart ds
on sl.its_number = ds.identifier cross join
site_file_sets sfs
WHERE sl.its_number != 'NULL' AND
sfs.name LIKE %{demandstar.identifier}%
ORDER BY sl.county ASC, sl.assoc_property ASC, sl.id ASC;
The next two problems are the lack of single quote around the like
pattern, and the != NULL
. The != NULL
will always return NULL
which is treated as false. This is the improved version:
SELECT sl.*, sfs.*, ds.identifier, ds.date_due
FROM surplusland_list sl join
demandstart ds
on sl.its_number = ds.identifier cross join
site_file_sets sfs
WHERE sl.its_number is not 'NULL' AND
sfs.name LIKE '%{demandstar.identifier}%'
ORDER BY sl.county ASC, sl.assoc_property ASC, sl.id ASC;
However, this will not do what you want until you replace the cross join
with an appropriate join
and on
clause.