Home  >  Article  >  Database  >  How to use built-in commands (G & g) and semicolon (;) together in one MySQL statement?

How to use built-in commands (G & g) and semicolon (;) together in one MySQL statement?

PHPz
PHPzforward
2023-09-10 15:45:151289browse

如何在一条 MySQL 语句中同时使用内置命令 (G & g) 和分号 (;)?

We know that the built-in commands (\G and \g) send the command to the MySQL server for execution, and with the help of the semicolon (;) MySQL determines the end of the statement. In order to use these three queries and get error-free results, we need to write three queries in one statement, one query using \G, one query using \g, and another query using a semicolon (;) at the end.

Example
mysql> Select * from student\G select * from ratelist\g select NOW();
*************************** 1. row ***************************
  Name: Gaurav
RollNo: 100
 Grade: B.tech
*************************** 2. row ***************************
  Name: Aarav
RollNo: 150
 Grade: M.SC
*************************** 3. row ***************************
  Name: Aryan
RollNo: 165
 Grade: M.tech
3 rows in set (0.00 sec)

+----+------+-------+
| Sr | Item | Price |
+----+------+-------+
| 1  | A    | 502   |
| 2  | B    | 630   |
| 3  | C    | 1005  |
| 4  | h    | 850   |
| 5  | T    | 250   |
+----+------+-------+
5 rows in set (0.00 sec)

+---------------------+
| NOW()               |
+---------------------+
| 2017-11-06 18:04:12 |
+---------------------+
1 row in set (0.00 sec)

In the above example, the MySQL statement encounters \G after the first query and throws a vertically formatted result set based on it, and then in the second query After \g is encountered, and based on it throws the result set in tabular format. After that, MySQL encounters the semicolon (;) and throws the result set in tabular form based on it.

This way, we can use all result sets in a single MySQL statement.

The above is the detailed content of How to use built-in commands (G & g) and semicolon (;) together in one MySQL statement?. 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