Dev DOS
Dev DOS

Reputation: 1068

How to select a column with a number name in a table with SQL

I have a column named 0 in the table mytable. I want to select the contains of this column. when I tried with:

 SELECT 0 FROM mytable WHERE key_id =  '8'

It didn't show the column's data but it shows only the value 0 but this column doesn't have the 0 value. How can I get the contents of this column?

Upvotes: 0

Views: 58

Answers (4)

Nagaraj S
Nagaraj S

Reputation: 13474

create table test(`0` INT,key_id int );

INSERT INTO test VALUES(1,8);

SELECT `0` FROM test where key_id=8;

SQL FIDDLE

Upvotes: 1

Abdul Manaf
Abdul Manaf

Reputation: 4888

create table test_0(`0` INT );

INSERT INTO test_0 VALUES(1);

SELECT `0` FROM test_0;
+------+
| 0    |
+------+
|    1 |
+------+
1 row in set (0.00 sec)

Upvotes: 2

user3305084
user3305084

Reputation:

Try this

mysql_query("select * from `mytable` where `key_id`=8")

Upvotes: 1

G one
G one

Reputation: 2729

Since zero is a number you need to specify it with the back ticks

SELECT `0` FROM mytable WHERE key_id = '8'

Upvotes: 3

Related Questions