简体   繁体   中英

MYSQL MULTIPLE TABLE JOIN USING pattern match / JOIN

I'm using a multi table select statement in mysql to filter query from some user inputs. The input $_POST values are: 1.zipcode [from locations table] or 2.city [from locations table] and/or 3.on_date [from calendar table] and /or 4.title [from posts table].

FROM table_many
INNER JOIN posts ON posts.title LIKE '%{$title}%'
INNER JOIN users ON users.user_id = posts.user_id
INNER JOIN locations ON locations.post_id = posts.post_id AND locations.city = '$city[0]'
LEFT JOIN calendar ON calendar.post_id = posts.post_id AND calendar.on_date = '$date'
LEFT JOIN uploads ON posts.post_id = uploads.post_id 
WHERE table_many.cat_id = '$row_cat[0]' AND table_many.post_id = posts.post_id";

This setup works for the locations. I can enter either a zipcode or a city and the query filters correctly, but the $date and $title values, which are set from the input, retrieve no records.

Any ideas? or do you need more info? Thanks in advance.

You left out tableName in title INNER JOIN posts ON title LIKE '%{$title}%'

try tableName.title .

I don't see anything with the query that will make it not work, but lemme have a look at it again

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM