
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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)
- Related Articles
- How do I select data from one table only where column values from that table match the column values of another table in MySQL?
- How do I see what character set a MySQL database  / table / column is?
- How can I replace & with an ampersand in my MySQL database?
- How do I add more members to my ENUM - type column in MySQL?
- How do I redirect my web page with JavaScript?
- How do I select four random tables from a MySQL database having thousands of tables?
- How do I alter a MySQL table column defaults?
- How should I store data into my Mysql database, what type should I assign to a column storing salt values?
- How do I select text nodes with jQuery?
- How do I see all foreign keys to a table column?
- Select some data from a database table and insert into another table in the same database with MySQL
- How Do I Make It So My Table Doesn\'t Format \"Wrong\" In HTML?
- How to select different values from same column and display them in different columns with MySQL?
- How do I show the schema of a table in a MySQL database?
- How do I INSERT INTO from one MySQL table into another table and set the value of one column?

Advertisements