Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem using the field 'from' in sql query

Tags:

mysql

SELECT m.id, m.title, m.message, m.from, m.to2, m.to_viewed, m.from_viewed, m.created, u.username 
FROM tbl_messages m 
INNER JOIN tbl_users u 
ON m.from = u.id WHERE m.to2 = '1' && m.to_saved = '1'  && m.to_deleted = '0' 
ORDER BY m.created DESC

Having removed m.from, the query runs. It doesn't like this field name. Is 'from' reserved? Could someone suggest a fix?

Thanks

like image 374
sark9012 Avatar asked Feb 22 '23 22:02

sark9012


1 Answers

Yes, it's one of the reserved words. Use backticks to quote it:

m.`from`
like image 147
Mark Byers Avatar answered Mar 04 '23 02:03

Mark Byers