tags:

views:

65

answers:

2

So I made a table with columns "from" and "to".

While writing to the table is fine because I am inserting one value into each column (and not referencing the columns by name), but whenever I want to retrieve data (SELECT), I want to retrieve... say, only the "from" column.

Except as you guessed, it interprets "from" as an SQL command instead of a column name. Surrounding it in quotes just makes "from" populate the result set. Weird.

Can I do anything short of renaming the column? (Which isn't too bad, since the table really has no real data right now).

Thanks!

What I have now: SELECT from,id FROM permissions

+13  A: 

Backticks should work in this situation.

e.g.

SELECT `from` FROM myTable;

But ideally you'd rename it. Perhaps to make it more descriptive also, e.g. "rangeFrom" or "dateFrom", etc.

mopoke
I didn't know that backtick trick. Thanks!
Nirmal
Other database systems use either [brackets], 'apostrophes', or "double quotes", but MySQL uses ``backticks``.
Eilon
+1 And for the record, never do this again :) Find a synonym instead: "Sender," and "Receiver" might have sufficed.
Jonathan Sampson
Cheers for that. I thought I'd tried everything...!
Julian H. Lam
+2  A: 
SELECT (`from`,`to`) FROM `permissions`

Update.

Whoops, seems like I'm too slow for this site.

johnnyArt
LOL! Isn't it good if SO had keyboard shortcuts?
Nirmal
I'm not used to it yet! And why can't I type ']' on a normal reply? That just gets on my nerves
johnnyArt