views:

103

answers:

3

My table is organised like this:

alt text

With key as the primary field. The records shown are in the renamed table.

I need to get out the original_name by the key. The key coluimn is the primary key of the table.

This is my SQL code:

SELECT original_name FROM `renamed` WHERE key='fb166'

However, it does not return any results. I have tried both through my PHP script and directly through phpMyAdmin and both return an empty result set.

Any help? :/

A: 

Try something like

SELECT '|' || key || '|'
FROM renamed
WHERE key LIKE '%fb166%'

and check if you get a result and how the key looks like...

Do you get any results with the following?

SELECT * FROM renamed
Peter Lang
That does bring back all the rows.
Matt
+5  A: 

key is a reserved word in MySQL. Have you tried:

SELECT original_name FROM `renamed` WHERE `key`='fb166'
ZoogieZork
Ah! That works. I forgot all about the possibility of reserved words. Thank you very much! :)
Matt
A: 
  1. The backticks are necessary as key is a keyword in mysql.

  2. As suggested try with WHERE key LIKE '%fb166%' as you column is of type text it s probably you have some other char in it.

  3. It s a bad idea to have a key with a type of text, you will not be able to make it a primary key or add an index to it.

Patrick
How to get the backticks in the code ?
Patrick