1

I have an MySQL query, which returns an error message. I think it could be due to the word "out". Normally, I would just change the field name but I am working on some software that I am not used to and I don't know how much of a change that would be. So, I want to be sure if I have to.

Here is the query:

SELECT * FROM probid_bids WHERE auctionid=73 AND out=0 AND invalid=0 

Here the error message:

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 'out=0 AND invalid=0' at line 1

3 Answers 3

4

OUT is indeed a reserved word. You can encase the column names in backticks to quote the names, and thus avoid this problem, like so:

SELECT * FROM probid_bids WHERE `auctionid`=73 AND `out`=0 AND `invalid`=0 
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for actually explaining the cause of the error, and explaining why the OP needs to escape out with backticks. I'm sick of one line answers, so thank you for posting one with a bit of detail.
3

OUT is a reserved word (it is used to specify the type of parameters -- IN, OUT, INOUT -- when creating procedures). Try enclosing it inside backticks (`).

The rules regarding how and when to quote the identifiers (table names, column names, etc) are described here.

Note: certain MySQL configurations allow you to use double quotes as well but this should be avoided; stick with using backticks to quote identifiers and single quotes to quote strings.

Comments

2

Escape the keys:

SELECT * FROM `probid_bids` WHERE `auctionid`=73 AND `out`=0 AND `invalid`=0 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.