1

I would like to retrieve data from a given index. Here's the sql code of the database:

 CREATE TABLE `test` (
 `index` int(11) NOT NULL AUTO_INCREMENT,
 `user` text NOT NULL,
 PRIMARY KEY (`index`),
 UNIQUE KEY `index` (`index`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1

I can retrieve data from user like this:

SELECT * FROM test WHERE user='bertrand'

but when I try with index like this:

'index'=1

it gives me nothing ! I don't understand what I'm doing wrong, any help would be appreciated, thanks.

Filipe Silva
  • 21,189
  • 5
  • 53
  • 68
user2216280
  • 73
  • 3
  • 11

2 Answers2

2

Just remove quotes. Now it returns nothing because 'index' doesn't equal 1. If you wrap a value it quotes, it will be considered as a string value.

SELECT * FROM test WHERE index=1

EDIT: Just noticed index is a reserved keyword. Also you have to rename that column.

Aycan Yaşıt
  • 2,106
  • 4
  • 34
  • 40
0

You can use index in your query, but as it is a reserved keyword, you have to wrap it in backticks, not singlequotes:

SELECT * FROM test WHERE `index`=1
Filipe Silva
  • 21,189
  • 5
  • 53
  • 68