I’m trying to perform the following query using MySQL:
SELECT e.event,
BINARY e.params as params,
UNIX_TIMESTAMP(e.datetime) AS datetime,
p.postid AS postid,
q.postid AS parentid
FROM qa_eventlog as e
LEFT JOIN qa_posts as p
LEFT JOIN qa_posts as q ON e.userid=1 AND
DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= datetime AND
e.params LIKE '%postid='+p.postid+'%' AND
e.params LIKE '%parentid='+q.postid+'%'
ORDER BY datetime DESC
but it gives the following error:
Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to
use near ‘+p.postid+’%’ AND e.params LIKE ‘%parentid=’+q.postid+’%’
ORDER BY datetime DESC’ at line 1
It seems it doesn’t like the + sign, which I thought was the correct way to add values in a query; guess not 🙂 How do I ask it to check if the column value of one table (an integer) is in the column value of another table (a string)?
Edit: Thanks for the answers, here’s the code that worked, using CONCAT:
SELECT e.event,
BINARY e.params as params,
UNIX_TIMESTAMP(e.datetime) AS datetime,
p.postid AS postid,
q.postid AS parentid
FROM qa_eventlog AS e
LEFT JOIN qa_posts AS p
ON e.params LIKE CONCAT('%postid=', p.postid, '%' )
LEFT JOIN qa_posts AS q
ON e.params LIKE CONCAT('%postid=', q.postid, '%' )
WHERE e.userid=1
AND DATE_SUB(CURDATE(),INTERVAL 30 DAY) <= datetime
ORDER BY datetime DESC
try this one,