
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Execute MySQL Query from the Terminal Without Printing Results
Let us first create a table −
mysql> create table DemoTable709 (Amount int); Query OK, 0 rows affected (0.62 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable709 values(100); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable709 values(560); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable709 values(7800); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable709 values(1020); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable709;
This will produce the following output -
+--------+ | Amount | +--------+ | 100 | | 560 | | 7800 | | 1020 | +--------+ 4 rows in set (0.00 sec)
Following is the query to execute MySQL query from the terminal without printing results −
mysql> set @TotalAmount=(select sum(Amount) from DemoTable709); Query OK, 0 rows affected (0.00 sec)
If you want to see the result, you can use below query −
mysql> select @TotalAmount;
This will produce the following output -
+--------------+ | @TotalAmount | +--------------+ | 9480 | +--------------+ 1 row in set (0.05 sec)
Advertisements