Home > Database > Mysql Tutorial > body text

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

PHPz
Release: 2023-09-10 15:45:15
forward
1186 people have browsed it

如何在一条 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!