-1

I've read the other MySQL reserved words questions that suggest using backticks when calling reserved words in MySQL.

Unfortunately, I've tried those and they haven't worked in my particular case where multiple tables/table aliases are being used. My query looks like:

select rf.id, `s.Status` as 'Status'
from form rf 
left outer join sharerequest rr on rr.formId = rf.id
left outer join schedule s on s.sharerequestid = rr.id

I've tried different variations of this (backticks around just the word "status", encapsulating it in brackets (like SQLServer)) and nothing has worked.

I'm pretty sure backticks are how I'm supposed to handle this but I'm not sure what I'm doing wrong here.

JakeHova
  • 1,189
  • 2
  • 15
  • 36
  • I couldn't see how you joined table b – Tayfun Yuksel Jun 21 '22 at 15:07
  • I suggest the reading of [this answer](https://stackoverflow.com/a/23446378/844212) to a question like yours. Those two options offered are perfectly explained. – VFG Jun 21 '22 at 15:07
  • 1
    Status is a keyword in mysql not a reserved word so doesn't need backticks ,also every node needs to be backticked if you do use backticks – P.Salmon Jun 21 '22 at 15:14
  • 1
    If you use them, both parts need to be back ticked`\`b\`.\`Status\`` as Status – RiggsFolly Jun 21 '22 at 15:18
  • You don't need to escape a reserved word if it's after a `.`. So you can just write `b.Status`. Except that `b` should be either `rr` or `s`. – Barmar Jun 21 '22 at 15:23
  • @RiggsFolly P.Salmon - Thank you! your two answers combined answered my question. – JakeHova Jun 21 '22 at 15:59

1 Answers1

1

For the record, this is covered in the MySQL manual here:

https://dev.mysql.com/doc/refman/8.0/en/identifier-qualifiers.html

If any components of a multiple-part name require quoting, quote them individually rather than quoting the name as a whole. For example, write `my-table`.`my-column`, not `my-table.my-column`.

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828