4
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

cillierscharl
  • 6,875
  • 3
  • 27
  • 45
sark9012
  • 5,247
  • 17
  • 57
  • 95
  • You should use backticks [`] with the keywords that are used as a column name or table name. – Ghazanfar Mir Sep 19 '11 at 11:54
  • possible duplicate of [Syntax error due to using a reserved word as a table or column name in MySQL](http://stackoverflow.com/questions/23446377/syntax-error-due-to-using-a-reserved-word-as-a-table-or-column-name-in-mysql) – Ian Ringrose May 06 '14 at 09:56

5 Answers5

3

Wrap it with backticks, because it is mysql's reserved keyword

m.`from`

Here is a full list of reserved words

zerkms
  • 240,587
  • 65
  • 429
  • 525
3

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

m.`from`
Mark Byers
  • 767,688
  • 176
  • 1,542
  • 1,434
1

From is reserved, yes. You could try adding quotes around it. The easiest is to avoid using reserved words in queries.

OptimusCrime
  • 14,324
  • 12
  • 54
  • 94
1

Yes it is a reserved word. You should enclose from in back ticks like

m.`from`
Jan S
  • 1,805
  • 15
  • 20
0

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).

Colin Fine
  • 3,316
  • 1
  • 19
  • 32