
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
Found 4381 Articles for MySQL

184 Views
For this, you can use COALESCE(). Let us first create a table −mysql> create table DemoTable1805 ( Name1 varchar(20), Name2 varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1805 values('Chris', NULL); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1805 values('David', 'Mike'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1805 values(NULL, 'Mike'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1805;This will produce the ... Read More

132 Views
For this, you can use GROUP BY clause. To find maximum value, use MAX() function. Let us first create a table −mysql> create table DemoTable1804 ( Id int, Marks1 int, Marks2 int, Marks3 int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1804 values(1, 56, 89, 34); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1804 values(1, 98, null, 94); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1804 values(2, 34, 45, 78); ... Read More

210 Views
For this, you can use CONCAT() with CURDATE().There is no function with the name CONTAINS() in MySQL.Let us first get the current date. The current date is as follows −mysql> select curdate();This will produce the following output −+------------+ | curdate() | +------------+ | 2019-11-28 | +------------+ 1 row in set (0.00 sec)We will now create a table −mysql> create table DemoTable1803 ( Name varchar(20), JoiningYear varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1803 values('Chris', '2020/2017'); Query OK, 1 row ... Read More

140 Views
For this, you can use DISTINCT keyword. Let us first create a table −mysql> create table DemoTable1801 ( Name varchar(20), Score int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1801 values('John', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John', 98); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('John', 99); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1801 values('Carol', 99); Query OK, 1 row affected (0.00 sec)Display all records ... Read More

531 Views
For alias, use the following syntax wherein we are display an alias name −select sum(yourColumnName) as anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable1800 ( Salary int ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1800 values(18000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1800 values(32000); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1800 values(50000); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * ... Read More

493 Views
For this, you can use group_concat() along with replace(). Let us first create a table −mysql> create table DemoTable1799 ( EmployeeId varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1799 values('101, 102, 103, 104'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1799 values('106, 109'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1799;This will produce the following output:+-----------------+ | EmployeeId | +-----------------+ | 101, 102, 103, ... Read More
Select some data from a database table and insert into another table in the same database with MySQL

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 the table using insert command −mysql> insert into DemoTable1 values(101, 'Chris', 24); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1 values(102, 'David', 28); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1;This will produce the following ... Read More

745 Views
For this, you can use TRUNCATE TABLE command. Let us first create a table −mysql> create table DemoTable1796 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1796(StudentName) values('Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1796(StudentName) values('David Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1796(StudentName) values('John Doe'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statementmysql> select ... Read More

187 Views
Let us first create a table −mysql> create table DemoTable1795 ( Name varchar(20), DueDate date ); Query OK, 0 rows affected (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1795 values('John', '2018-07-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1795 values('Sam', '2019-10-21'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1795 values('Sam', '2019-01-10'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1795 values('Mike', '2018-12-31'); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> ... Read More

177 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 row affected (0.00 sec) mysql> insert into DemoTable1794 values(80); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1794 values(320); Query OK, 1 row affected (0.00 sec)Display all records from the table using select statement −mysql> select * from DemoTable1794;This will produce the following output −+--------+ | Amount | ... Read More