Here is my simple Inner Join:
SELECT paintings.*, locations.*
FROM paintings
INNER JOIN locations
ON locations.work_type = 'paintings' AND locations.work_id = 'paintings.id'
WHERE locations.location LIKE '%19th%'
It returns zero results. I expect it to find every painting row that has a match in locations table, based on having a common work_type and id. I know there are matches because
SELECT * FROM locations WHERE location LIKE '%19th%' AND work_type = 'paintings'
I get 1000+ results.
What am I doing wrong?
Thanks…
You need to change this part:
to this:
Your current query requires that the
locations.work_idfield contain the actual literal value “paintings.id”; what you want is to require that thelocations.work_idfield contain the same value as thepaintings.idfield.