-2

I have a table and I'm trying to retrieve any row which has a number in it

For example this:

+----------+--------------+
| Name     | age          | 
+----------+--------------+
| name1    |      21      | 
| name2    |      22      | 
| name3    |      21      |
+----------+--------------+

I tried this:

SELECT * FROM table WHERE 'age' = 21;

the message I get from the is

Empty set, 1 warning (0.00 sec)

I'm not to sure what I'm doing wrong?

4

4 回答 4

2

The issue is 'age'. You don't need to use quotes near age.

SELECT * from Table1 where age = 21;

See this SQLFiddle.

Instead of quotes you can use Backtick (`).
Also, Don't use Reserved Words as you use in table name.

于 2012-10-16T10:03:48.587 回答
2

Don't add quotes to your column name use like this

SELECT * FROM table WHERE age = 21;
于 2012-10-16T10:05:31.907 回答
2

Instead of using 'age' simply use age it works

Use this:

SELECT * FROM table WHERE age = 21;
于 2012-10-16T10:05:53.697 回答
1

Try this

select * from person where age = 20;

SQL fiddle: http://sqlfiddle.com/#!2/0d3c32/24

于 2012-10-16T10:08:05.853 回答