-1

I have a database with the fields: land, zone, domestic. And I want to get all this info out depending on what land the user chooses. So I figured I do this: SELECT * FROM myDB WHERE land=Norway (Norway is a stored country).

But I get the error unknown column Norway. Is this because it cant find Norway or what seems to be the problem?

mrfr
  • 1,724
  • 2
  • 23
  • 44

5 Answers5

5

It looks like you aren't specifying a table name try something like this:

SELECT * FROM MyDB.MyTable 
WHERE land = 'Norway'

Also note that string Norway is in single quotes

SaggingRufus
  • 1,814
  • 16
  • 32
2

You missed the single quotes before and after the country name that you've used, as per my comment on the question earlier!

SELECT * FROM myDB WHERE land = 'Norway'

The above query works on the assumption that your table is actually named as myDB

N00b Pr0grammer
  • 4,503
  • 5
  • 32
  • 46
1

You need quotes around literal

SELECT * FROM myDB.tablename WHERE land='Norway';

(and a proper tablename) otherwise your value is used like a column name and give your the error Unknown column Norway.

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
0

You are query using a where clause that confront a column with text. So to compare you have to tell to the dbms the value to match . Using only Norway it doesn't understand that you are asking for the row with Norway value. Using 'Norway' you are telling "hey dbms here you are your text to confront". I hope that I'm to help.

P.Carlino
  • 661
  • 5
  • 21
-1

You can use ` marks for choosing columns/tables, so you should do something like

SELECT `column1`,`column2` FROM `tablename` WHERE `column`="value"
gyurix
  • 1,106
  • 9
  • 23
  • `Using single quotes for string literals is defined (and required) by the SQL standard`. [reference](http://stackoverflow.com/a/11321508/3536236) . While double quotes will work (and this surprised me) and are technically not wrong, it's not at all best practise. – Martin Feb 22 '17 at 19:43