Eleeist
Eleeist

Reputation: 7041

SQL query in Java (WHERE)

I am trying to select all rows that have "helloworld" in "category" column. Here is my query:

SELECT * FROM `commands` WHERE `category` = `helloworld`

I get this error:

Unknown column 'helloworld' in 'where clause'

I would appreciate any help.

Upvotes: 0

Views: 96

Answers (3)

aacanakin
aacanakin

Reputation: 2913

I think you don't need to have '' fields that are non - variables. Just try this ;

SELECT * FROM commands WHERE category = "helloworld"

Upvotes: 0

Joachim Isaksson
Joachim Isaksson

Reputation: 181077

That should be

SELECT * FROM `commands` WHERE `category` = 'helloworld'

Note the difference in quotes. Strings are quoted with ' while table/column names can optionally be quoted with ` to avoid being interpreted as keywords.

Upvotes: 0

Robin
Robin

Reputation: 36621

Try with

SELECT * FROM `commands` WHERE `category` = 'helloworld'

instead. Note the ' around helloworld instead of `

Upvotes: 4

Related Questions