简体   繁体   中英

MySQL how to get a specific row from a table

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?

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

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

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.

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.

您可以使用`标记来选择列/表,因此您应该执行类似

SELECT `column1`,`column2` FROM `tablename` WHERE `column`="value"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM