MySQL Articles

Page 74 of 355

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?

Nishtha Thakur
Nishtha Thakur
Updated on 22-Jun-2020 158 Views

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. It is also known that both of them have different format of the result set. For combining them and getting the result without error, we need to write two queries, one query with either \G or \g and other with a semicolon (;) at the end, in a single statement.ExampleCombining \G and Semicolon (;) −mysql> Select * from student\G select * from ratelist; *************************** 1. row ***************************   Name: Gaurav ...

Read More

In MySQL, how we can get the total value by category in one output row?

Srinivas Gorla
Srinivas Gorla
Updated on 22-Jun-2020 151 Views

With the help of the MySQL SUM() function, we can get the total value by category in one output row. For example in table ‘ratelist’ if we want to get the total value of category ‘price’ then we can use SUM() on price as follows −mysql> select SUM(price) as totalprice from ratelist; +------------+ | totalprice | +------------+ |       3237 | +------------+ 1 row in set (0.00 sec)The query above returns the total value of price in one output row.

Read More

How MySQL manage the behavior of a transaction?

Kumar Varma
Kumar Varma
Updated on 22-Jun-2020 149 Views

MySQL can manage the behavior of a transaction with the help of the following two modes −Autocommit OnIt is the default mode. In this mode, each MySQL statement (within a transaction or not) is considered as a complete transaction and committed by default when it finishes. It can be started by setting the session variable AUTOCOMMIT to 1 as follows −SET AUTOCOMMIT = 1 mysql> SET AUTOCOMMIT = 1; Query OK, 0 rows affected (0.07 sec)Autocommit OffIt is not the default mode. In this mode, the subsequent series of MySQL statements act like a transaction, and no activities are committed ...

Read More

While using the ROLLUP modifier, is it possible to use a MySQL ORDER BY clause to sort the result?

usharani
usharani
Updated on 22-Jun-2020 521 Views

Actually ROLLUP and ORDER BY are mutually exclusive in MySQL hence it is not a good practice to use both of them in a query. But still, if we use ROLLUP in ORDER BY then the main disadvantage is that the summary rows would get sorted along with the rows they are calculated. It is also significant to notice that the sort order will decide the position of summary rows.The summary rows would be at the beginning of ascending order and at the end of descending order. Consider the following example to understand it more clearly −mysql> Select * from ...

Read More

What would be the effect on summary output when I use explicit sort order (ASC or DESC) with column names in the GROUP BY list along with "WITH ROLLUP" modifier?

Nikitha N
Nikitha N
Updated on 22-Jun-2020 191 Views

In the case, where we use explicit sort order (ASC or DESC) with column names in the GROUP BY list along with the “WITH ROLLUP” modifier, the summary rows added by ROLLUP still appear after the rows from which they calculated regardless of the sort order.As we know that the default sort order is ascending hence in the example below if we will not use any explicit sort order then the output would be as follows −mysql> Select sr, SUM(Price) AS Price from ratelist Group by sr with rollup; +-----+-------+ | sr  | Price | +-----+-------+ |  1  |   ...

Read More

Which statement, other than START TRANSACTION, is used for starting a transaction?

Sharon Christine
Sharon Christine
Updated on 22-Jun-2020 272 Views

We can also use the BEGIN statement to start a new transaction. It is the same as the START TRANSACTION statement.Examplemysql> BEGIN; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO Marks Values(1, 'Aarav', 'History', 40); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO Marks Values(2, 'Harshit', 'History', 48); Query OK, 1 row affected (0.00 sec) mysql> ROLLBACK; Query OK, 0 rows affected (0.04 sec)In this example, the transaction is initiated by the BEGIN Statement rather than START TRANSACTION statement. Two INSERT statements are then executed followed by a ROLLBACK statement. ROLLBACK statement will ...

Read More

How can MySQL produce the output in a vertical format rather than tabular format?

varma
varma
Updated on 22-Jun-2020 593 Views

By using \G at the end of MySQL statement, it returns the output in a vertical format rather than a tabular format. Consider the example below −mysql> Select curdate(); +------------+ | curdate()  | +------------+ | 2017-11-06 | +------------+ 1 row in set (0.00 sec) mysql> Select CURDATE()\G *************************** 1. row *************************** CURDATE(): 2017-11-06 1 row in set (0.00 sec)From the example above, the difference of using \G at the end of the MySQL statement can be understood. It returns the same output in a vertical format rather than a tabular format.

Read More

How does MySQL determine the end of the statement?

Govinda Sai
Govinda Sai
Updated on 22-Jun-2020 216 Views

MySQL determines the end of a statement when it encounters any one of the followings −Semicolon(;)Generally, MySQL determines the end of the statement, single-line or multiple-line, when it encounters the termination semicolon(;). Consider the examples below, mysql> Select * from employee; (Single line statement) mysql> Select *     -> from     -> employee; (Multiple line statement)In both cases, MySQL returns the result set after encountering the semicolon, which means the end of the statement.\G option\G option means to send the current state to the server to be executed and display the result in a vertical format. When we ...

Read More

How can I use MySQL subquery as a table in FROM clause?

Monica Mona
Monica Mona
Updated on 22-Jun-2020 295 Views

We can use a subquery as a table in the FROM clause in the same way as the result of a subquery can be used with an operator in the WHERE clause. In the following example, we are using the result of subquery as a table by writing it after the FROM clause. It is mandatory to use an alias after subquery, here we are using alias ‘C_car’. To demonstrate it we are using the data as follows from table ‘Cars’ −mysql> Select * from Cars; +------+--------------+---------+ | ID | Name ...

Read More

How can I display MySQL query result vertically?

Abhinaya
Abhinaya
Updated on 22-Jun-2020 903 Views

With the use of ego, \G option at end of a statement, we can get the result set in vertical format. Consider the following example −mysql> Select * from Student where name = 'Aarav'\G *************************** 1. row *************************** Name: Aarav RollNo: 150 Grade: M.SC 1 row in set (0.00 sec)

Read More
Showing 731–740 of 3,547 articles
« Prev 1 72 73 74 75 76 355 Next »
Advertisements