- 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 4378 Articles for MySQL
673 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
138 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
6K+ Views
For this, you can use TIMESTAMP keyword in MySQL.Let us create a table −mysql> create table demo50 −> ( −> id int not null auto_increment primary key, −> start_date timestamp default current_timestamp not null, −> end_date timestamp default current_timestamp not null −> ); Query OK, 0 rows affected (1.35 sec)Insert some records into the table with the help of insert command −mysql> insert into demo50 values(); Query OK, 1 row affected (0.15 sec) mysql> insert into demo50(end_date) values('2020−12−21'); Query OK, 1 row affected (0.07 sec) mysql> insert into demo50(start_date) values('2020−01−01'); Query OK, 1 row affected (0.14 sec)Display records ... Read More
163 Views
For this, use concat() along with LIKE. Following is the syntax −select *from yourTableName where concat(', ', yourColumnName, ', ') like '%, yourValue, %';Let us create a table −mysql> create table demo49 −> ( −> id varchar(20) −> , −> first_name varchar(20) −> ); Query OK, 0 rows affected (1.45 sec)Insert some records into the table with the help of insert command −mysql> insert into demo49 values('4, 5, 6', −> 'Adam'); Query OK, 1 row affected (0.20 sec) mysql> insert into demo49 values('5, 3, 2', 'Mike'); Query OK, 1 row affected (0.19 sec) mysql> insert into demo49 values('3, ... Read More
89 Views
For appending, use the concept of concat(). The syntax is as follows −select *from yourTableName where yourColumnName like concat('%', yourValue, '%');Let us create a table −mysql> create table demo48 -> ( −> id int not null auto_increment primary key, −> name varchar(20) −> ); Query OK, 0 rows affected (0.70 sec)Insert some records into the table with the help of insert command −mysql> insert into demo48(name) values('John Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo48(name) values('John Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo48(name) values('Adam Smith'); Query OK, 1 row ... Read More
400 Views
Let’s say we tried creating a table with name “groups”, which is a reserved keyword in MySQL You cannot use “groups” because groups is a reserved keyword in MySQL.Following error occurred while creating a table with name “groups” −mysql> create table groups −> ( −> id int, −> name varchar(40) −> ); ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'groups ( id int, name varchar(40) )' at line 1In order to create a table with reserved keyword, you need ... Read More
114 Views
For this, use CASE WHEN statement in MySQL. Let us create a table −mysql> create table demo47 −> ( −> first_name varchar(20), −> last_name varchar(20) −> ); Query OK, 0 rows affected (1.57 sec)Insert some records into the table with the help of insert command −mysql> insert into demo47 values('John', 'Smith'); Query OK, 1 row affected (0.18 sec) mysql> insert into demo47 values('David', 'Miller'); Query OK, 1 row affected (0.11 sec) mysql> insert into demo47 values('John', 'Doe'); Query OK, 1 row affected (0.12 sec) mysql> insert into demo47 values('Chris', 'Brown'); Query OK, 1 row affected (0.12 sec)Display ... Read More