I used ‘from’ and ‘to’ with backticks as column titles in my database table. Now, how do I SELECT them?


At first, to use reserved words, it should be set with backticks like −

`from`
`to`

Since you want to select the column names set with backtick as shown above, you need to implement the following −

select `to`,`from` from yourTableName;

Let us first create a table with column names as from and to with backticks −

mysql> create table DemoTable720 (
   `from` date,
   `to` date
);
Query OK, 0 rows affected (0.69 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable720 values('2019-01-21','2019-07-23');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable720 values('2017-11-01','2018-01-31');
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable720 values('2015-08-11','2016-09-19');
Query OK, 1 row affected (0.12 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable720;

This will produce the following output -

+------------+------------+
| from       | to         |
+------------+------------+
| 2019-01-21 | 2019-07-23 |
| 2017-11-01 | 2018-01-31 |
| 2015-08-11 | 2016-09-19 |
+------------+------------+
3 rows in set (0.00 sec)

Following is the query to select “to” and “from” −

mysql> select `to`,`from` from DemoTable720;

This will produce the following output -

+------------+------------+
| to         | from       |
+------------+------------+
| 2019-07-23 | 2019-01-21 |
| 2018-01-31 | 2017-11-01 |
| 2016-09-19 | 2015-08-11 |
+------------+------------+
3 rows in set (0.00 sec)

Updated on: 22-Aug-2019

74 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements