- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- 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 6702 Articles for Database
148 Views
For this, use INSERT INTO SELECT statement in MySQL. Let us create a table −mysql> create table demo61 −> ( −> id int, −> name varchar(20) −> ) −> ; Query OK, 0 rows affected (1.84 sec)Insert some records into the table with the help of insert command −mysql> insert into demo61 values(1, 'John'); Query OK, 1 row affected (0.63 sec) mysql> insert into demo61 values(2, 'David'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo61 values(1, 'Mike'); Query OK, 1 row affected (0.10 sec) mysql> insert into demo61 values(2, 'Carol'); Query OK, 1 row ... Read More
401 Views
Following is the syntax −select yourColumnName1, yourColumnName2, yourColumnName3, . . . N from yourTableName where yourValue in(yourColumnName1, yourColumnName2) or yourColumnName1 is NULL;Let us create a table −mysql> create table demo60 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ) −> ; Query OK, 0 rows affected (2.11 sec)Insert some records into the table with the help of insert command −mysql> insert into demo60(first_name, last_name) values('John', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo60(first_name, last_name) values('John', 'Doe'); Query OK, 1 row affected (0.51 sec) mysql> insert ... Read More
145 Views
To store the exact real value, you need to use truncate() with 2 decimal point. Let us create a table −Following is the query to create a table.mysql> create table demo59 −> ( −> price decimal(19, 2) −> ); Query OK, 0 rows affected (1.12 sec)Insert some records into the table with the help of insert command −mysql> insert into demo59 values(truncate(15.346, 2)); Query OK, 1 row affected (0.14 sec) mysql> insert into demo59 values(truncate(20.379, 2)); Query OK, 1 row affected (0.72 sec) mysql> insert into demo59 values(truncate(25.555, 2)); Query OK, 1 row affected (0.16 sec) mysql> ... Read More
183 Views
Fir this, use CASE WHEN statement in MySQL correctly. Let us see how.Let us create a table −mysql> create table demo58 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ); Query OK, 0 rows affected (2.15 sec)Insert some records into the table with the help of insert command −mysql> insert into demo58(first_name, last_name) values('John', 'Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo58(first_name, last_name) values('David', 'Smith'); Query OK, 1 row affected (0.29 sec) mysql> insert into demo58(first_name, last_name) values('John', 'Brown'); Query OK, 1 row affected (0.11 ... Read More
101 Views
For this, you can use ORDER BY. Let us create a table −mysql> create table demo57 −> ( −> id int not null auto_increment primary key, −> full_name varchar(20) −> ); Query OK, 0 rows affected (1.60 sec)Insert some records into the table with the help of insert command −mysql> insert into demo57(full_name) values('John Smith'); Query OK, 1 row affected (0.24 sec) mysql> insert into demo57(full_name) values('David Miller'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo57(full_name) values('Not Known'); Query OK, 1 row affected (0.13 sec) mysql> insert into demo57(full_name) values('Chris Brown'); Query OK, 1 ... Read More
674 Views
Following is the syntax −insert into yourTableName values(yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), . . . NLet us create a table −mysql> create table demo56 −> ( −> id int, −> first_name varchar(20), −> last_name varchar(20), −> age int −> ); Query OK, 0 rows affected (1.91 sec)Insert some records into the table with the help of insert command −mysql> insert into demo56 values(1, 'John', 'Smith', 23), −> (2, 'David', 'Miller', 21), −> (3, 'Chris', 'Brown', 22), −> (4, 'Carol', 'Taylor', 20); Query OK, 4 rows affected (0.10 sec) Records: 4 Duplicates: 0 Warnings: ... Read More
1K+ Views
For this, you can use UPDATE command along with JOIN.Let us create the first table −mysql> create table demo54 −> ( −> firstName varchar(20), −> lastName varchar(20) −> ); Query OK, 0 rows affected (0.57 sec)Insert some records into the table with the help of insert command −mysql> insert into demo54 values('John', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo54 values('John', 'Smith'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo54 values('David', 'Smith'); Query OK, 1 row affected (0.11 sec)Display records from the table using select statement −mysql> select *from demo54;This will ... Read More
361 Views
To join tables, use the JOIN concept in MySQL. At first, let us create two tables.Let us create the first table −mysql> CREATE TABLE `demo52` ( −> `id` INT NOT NULL, −> `name` VARCHAR(20) NOT NULL, −> PRIMARY KEY (`id`) −> ); Query OK, 0 rows affected (1.19 sec)Insert some records into the table with the help of insert command −mysql> insert into demo52 values(1, 'John'); Query OK, 1 row affected (0.17 sec) mysql> insert into demo52 values(2, 'David'); Query OK, 1 row affected (0.10 sec) mysql> insert into demo52 values(3, 'Mike'); Query OK, 1 row affected (0.13 ... Read More
32 Views
For this, use ORDER BY CASE WHEN statement.Let us create a table −mysql> create table demo51 −> ( −> id int not null auto_increment primary key, −> name varchar(20) −> ); Query OK, 0 rows affected (1.08 sec)Insert some records into the table with the help of insert command −mysql> insert into demo51(name) values('John'); Query OK, 1 row affected (0.15 sec) mysql> insert into demo51(name) values('Bob'); Query OK, 1 row affected (0.09 sec) mysql> insert into demo51(name) values('David'); Query OK, 1 row affected (0.35 sec) mysql> insert into demo51(name) values('Sam'); Query OK, 1 row affected (0.14 sec)Display ... Read More
139 Views
At first, you need to extract the last digit and add the extracted value. And the same goes in till we get the sum of all digits of the year, for example, for the year 2020 −2 + 0 + 2 + 0 = 4The concept is as follows to extract the last digit from the year. Following is the query −select floor(@yourVariableName % 10);Following is the query to sum the digits of year −mysql> set @year_column_value = 2020; Query OK, 0 rows affected (0.00 sec) mysql> select −> floor(@year_column_value / 1000) −> + floor(@year_column_value % 1000 / 100) −> ... Read More