2011-06-24 69 views
5

我花了好幾個小時試圖解決這個問題。這個SQL有什麼問題?

SELECT * 
FROM `users` 
WHERE `IP` = `123.231.213.132` 

這是什麼問題?

#1054 - Unknown column '123.231.213.132' in 'where clause' 

回答

19

您不應該使用帶列值的反引號。您必須使用單引號或雙引號,否則mysql會將該值視爲列名稱。

SELECT * 
FROM `users` 
WHERE `IP` = '123.231.213.132' 
+3

多麼愚蠢的錯誤。 – Vercas

7

使用單引號,而不是反引號字符`123.231.213.132``

SELECT * 
FROM `users` 
WHERE `IP` = '123.231.213.132' 
1

It might be the single speach mark symbol. Try replacing them manually.

3

Use quotes ' not backticks ` for string literals

2

What's with the backticks? Use single quotes Also I'm assuming that users is a table name and IP is an entity of users.

Also...you have to end your statement with a semi-colon

1

you are using wrong quotation characters

to specify string value in mysql statement you have to use either '(single quote) or "(double quote)

`(backtick) characters are used to explicitly specify that quoted string represents a field name from where mysql should get the data

backticks are required in your statements if column names are conflicting with mysql's reserved keywords like indexwhere