
- 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
How can we use both built-in-commands (G & g) and semicolon (;) in a single MySQL statement?
As we know that built-in-commands (\G and \g) send the command to MySQL server for execution and with the help of Semicolon (;) MySQL determines the end of the statement. For using all three and getting the result without error, we need to write three queries, one query with \G, one with \g and other with a semicolon (;) in the end, in a single statement.
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 example above, MySQL statement encounters \G after the first query, and based on it throws the result set in vertical format and then encounters \g after the second query and based on it throws the result set in tabular format. After that MySQL encounters semicolon (;) and based on it throws the result set in tabular form.
In this way, we can use all of them in a single MySQL statement.
- Related Articles
- What happens if I use both G and semicolon (;) termination symbol with a single MySQL statement?
- How can I combine built-in-commands (g and G), used for executing a MySQL statement, with termination symbol semicolon (;) to get output without any error?
- How can I combine the built-in-commands (g and G), used for executing a MySQL statement, with each other?
- How can we run a MySQL statement without termination semicolon?
- Can we use semicolon as a MySQL DEMILITER?
- Can we use WHERE, AND & OR in a single MySQL query?
- Can we use SELECT NULL statement in a MySQL query?
- How can we use a MySQL subquery with INSERT statement?
- Instead of using a semicolon (;) terminator symbol, is there any other built-in-commands which execute the MySQL query?
- Can we use ADD and CHANGE with ALTER Statement in MySQL?
- How can we use SIGNAL statement with MySQL triggers?
- How can we use MySQL SELECT statement to count number of rows in a table?
- How can we update columns values on multiple rows with a single MySQL UPDATE statement?
- Can we use WHERE clause inside MySQL CASE statement?
- In MySQL, how we can write Multiple-line statement?
