Home  >  Article  >  Database  >  How to select data from a table with spaces in the table name in MYSQL?

How to select data from a table with spaces in the table name in MYSQL?

PHPz
PHPzforward
2023-09-03 11:13:06837browse

How to select data from a table with spaces in the table name in MYSQL?

If the table name has spaces, you need to use backticks around the table name. Let's first create a table.

Here, we have used backtick-

mysql> create table `Demo Table138`
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   Price int
);
Query OK, 0 rows affected (0.47 sec)

Use insert command to insert records in table-

mysql> insert into `Demo Table138`(Price) values(450);
Query OK, 1 row affected (0.18 sec)
mysql> insert into `Demo Table138`(Price) values(499);
Query OK, 1 row affected (0.16 sec)
mysql> insert into `Demo Table138`(Price) values(199);
Query OK, 1 row affected (0.17 sec)
mysql> insert into `Demo Table138`(Price) values(3090);
Query OK, 1 row affected (0.21 sec)

Use select command to display records in table-

The following is a query to select data from a table that contains spaces in the table name-

mysql> select *from `Demo Table138`;

This will produce the following output-

+----+-------+
| Id | Price |
+----+-------+
| 1  | 450   |
| 2  | 499   |
| 3  | 199   |
| 4  | 3090  |
+----+-------+
4 rows in set (0.00 sec)

The above is the detailed content of How to select data from a table with spaces in the table name in MYSQL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete