Problem using the field 'from' in sql query
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开发者_Python百科 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
Yes, it's one of the reserved words. Use backticks to quote it:
m.`from`
Wrap it with backticks, because it is mysql's reserved keyword
m.`from`
Here is a full list of reserved words
From is reserved, yes. You could try adding quotes around it. The easiest is to avoid using reserved words in queries.
Yes it is a reserved word. You should enclose from in back ticks like
m.`from`
Yes, "from" is reserved. In mysql, IIRC you can put it in either double quotes (") or backquotes (`) (but I also use postgresql, so I may be confusing the two systems).
精彩评论