1

I have a table with a column named 'from'. I want to retrieve data from it and so I tried following query.

select title,from,grade from localcourses where title='new';

But I get following exception due to the column name 'from'.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from,grade from localcourses where title='new'

How can I avoid this without renaming the column name? Thank you.

0

6 Answers 6

3

Try --

select `title`,`from`,`grade` from localcourses where `title`='new';
Sign up to request clarification or add additional context in comments.

Comments

3

If you are running MySQL in standard (ANSI) mode, use double quotes to "escape" the keyword:

select title,
       "from",
       grade 
from localcourses 
where title='new';

If you are running MySQL in non-standard mode (which is still the default if I'm not mistaken), you need to use MySQL's dreaded "backticks:

select title,
       `from`,
       grade 
from localcourses 
where title='new';

2 Comments

I tried both ways. But both give the same result as follows. title from grading \n title from grading \n title from grading \n title from grading \n title from grading
Then there is something you are not showing us. In which client application do you run that statement?
2

On MySQL you can use the ` (back apostrophe -- to the left of the 1 key on your keyboard). Use

`from`.

1 Comment

(back apostrophe -- to the left of the 1 key on your keyboard) was the missed point. Thanks.
2

I'll be the first to say it - you should avoid naming tables, columns, triggers, procedures, functions, etc with the names of reserved, action, and other commonly used words in sql and database engine syntax. It only creates confusion such is the case here.

Comments

1

Assuming Oracle try

select title,"from",grade from localcourses where title='new';

Comments

1

In mySQL, you need to enclose the from column in backtick character

select title,`from`,grade from localcourses where title='new'

I suspect the backtick character you are using is not the right one, I am not sure what type of keyboard you have, so it might not send the proper character in.

Try this instead.

select title,localcourses.from,grade from localcourses where title='new'

and see if that helps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.