Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I used "from" and "to" as column titles in my database table, how do I SELECT them?

Tags:

mysql

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

like image 441
Julian H. Lam Avatar asked Nov 22 '25 04:11

Julian H. Lam


1 Answers

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.

like image 75
mopoke Avatar answered Nov 23 '25 23:11

mopoke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!