I have a table named \'test\'
It contains a column named \'AND\'
For that I use the following queries
insert into test values (\'a\',\'abc\')
Don't create columns with a name that is a keyword.
If you do create a column with such a name, use backticks (MySQL only) or double quotes (SQL standard) to enclose the name. I'm not certain whether you need to switch on some mechanism to have double quotes work in MySQL. This creates a 'delimited identifier'.
SELECT `AND` AS a, "AND" AS b
FROM test;
See also:
Its a SO old question and solved. Read here more.
But still you can Try this :
select your_tablename.column_name from table_name;
Your code :-
select test.AND from test;
use backtick
to escape keyword instead. just like how you created your table. using double quote or single quote will parse it into string
that is why you're getting two records of and
select `AND` from test;
From your question:
CREATE TABLE `test` (
`count` VARCHAR(50) NULL DEFAULT NULL,
`AND` VARCHAR(50) NULL DEFAULT NULL
----^---^ Why do you use `backtick` (`) in CREATE TABLE statement?
)
Same way you need to use backtick
in SELECT
statement.
SELECT `AND` FROM test;
-------^---^-----------
See MySQL: Reserved Words
If you want to use reserved word as column, you must use backtick around the reserved word column.....
In your case, you have to do like this:
select `AND' from test;
If you use select setement using "" it select a given sting so you have to give a column name like in mssql you have to use
select [AND] from test;
or in mysql syntex
select AND
from test;