
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
AmitDiwan has Published 10744 Articles
Select some data from a database table and insert into another table in the same database with MySQL

AmitDiwan
700 Views
To insert data from a table to another, use INSERT INTO statement. Let us first create a table −mysql> create table DemoTable1 ( Id int, FirstName varchar(20), Age int ); Query OK, 0 rows affected (0.00 sec)Insert some records in ... Read More

AmitDiwan
179 Views
For this, you can use case statement. Let us first create a table −mysql> create table DemoTable1794 ( Amount int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1794 values(100); Query OK, 1 ... Read More

AmitDiwan
1K+ Views
To avoid any issues while running a query, use IFNULL(). Let us first create a table −mysql> create table DemoTable1793 ( StudentFirstName varchar(20), StudentLastName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> ... Read More

AmitDiwan
121 Views
To select not-null records, use IS NOT NULL property. Let us first create a table −mysql> create table DemoTable1792 ( Name varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1792 values('John Smith'); ... Read More

AmitDiwan
707 Views
For this, you can use aggregate function sum() along with parameter value for specific column. Let us first create a table −mysql> create table DemoTable1790 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(20), Score int ); Query OK, ... Read More

AmitDiwan
294 Views
Let us first create a table −mysql> create table DemoTable -> ( -> DueDate date -> ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-11'); Query OK, 1 row affected (0.08 sec) mysql> insert into ... Read More

AmitDiwan
522 Views
To drop a primary key, use ALTER at first to alter the table. With that, use DROP to drop the key as in the belowSyntaxalter table yourTableName drop primary key;Let us first create a table −mysql> create table DemoTable -> ( -> StudentId int NOT NULL, -> ... Read More

AmitDiwan
346 Views
To get the database name, use the below given syntax −select database();Let us implement the above syntax in the stored procedure −mysql> delimiter // mysql> create procedure get_procedure_database_name() -> begin -> select concat('The database name=', database()); -> end -> // Query OK, 0 rows affected (0.34 ... Read More

AmitDiwan
440 Views
Let’s say, here I am using the WEB database. We need to find the number of tables in the database WEB. For this, use the INFORMATION_SCHEMA.TABLES in MySQL.Following is the query to display the number of tables −mysql> select count(table_name) as TotalNumberOfTablesInWebDatabase -> from information_schema.tables -> where table_schema='web';This ... Read More

AmitDiwan
630 Views
To sum, use the aggregate function SUM(). With that, group using MySQL GROUP BY. Let us first create a table −mysql> create table DemoTable -> ( -> ProductName varchar(20), -> ProductQuantity int, -> ProductPrice int -> ); Query OK, 0 rows affected (0.63 sec)Insert some ... Read More