- 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
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
186 Views
Yes, you can use SUM() with IF() in MySQL. Let us first create a demo table:mysql> create table DemoTable ( Value int, Value2 int ); Query OK, 0 rows affected (0.51 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(100, 400); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(100, 400); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(400, 100); Query OK, 1 row affected (0.14 sec)Following is the query to display records from the table using select command:mysql> select *from DemoTable;This ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
334 Views
You can use aggregate function SUM() for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstValue int, SecondValue int, ThirdValue int ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue) values(10, 20, 30); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue) values(60, 50, 40); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(FirstValue, SecondValue, ThirdValue) values(80, 90, 100); Query OK, 1 row affected ... Read More
![Krantik Chavan](https://www.tutorialspoint.com/assets/profiles/13545/profile/60_126883-1512724834.jpg)
138 Views
In MySQL, COUNT() will display the number of rows. DISTINCT is used to ignore duplicate rows and get the count of only unique rows.Let us first create a table:mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(10) ); Query OK, 0 rows affected (0.47 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(FirstName) values('Larry'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName) values('Sam'); Query OK, 1 row affected (0.13 sec) ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
165 Views
You can use LIKE operator with wildcards to select the records where last value in a string = x, for example ‘10’, ‘15’, etc.Let us first create a table −mysql> create table DemoTable ( ClientId varchar(20) ); Query OK, 0 rows affected (0.68 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('CLI-101'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-110'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-201'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('CLI-210'); Query OK, 1 row affected (0.13 sec) ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
124 Views
You can use modify command for this. Let us first us create a table.mysql> create table DemoTable ( StudentId varchar(200) not null, StudentName varchar(20), StudentAge int, StudentAddress varchar(20), StudentCountryName varchar(20) ); Query OK, 0 rows affected (0.73 sec)Now check the description of table.mysql> desc DemoTable;This will produce the following output −+--------------------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +--------------------+--------------+------+-----+---------+-------+ | StudentId | varchar(200) | NO | | NULL | ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
486 Views
Use the concept of IFNULL() method to treat NULL as 0. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value1 int, Value2 int ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value1, Value2) values(10, 20); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Value1, Value2) values(null, null); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Value1, Value2) values(40, null); Query OK, 1 row affected (0.18 sec)Following is the query to display all ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
440 Views
You can use the concept of IFNULL() for this. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100) DEFAULT 'Larry', Age int DEFAULT NULL ); Query OK, 0 rows affected (0.73 sec)Insert records in the table using insert command −mysql> insert into DemoTable(Name, Age) values('John', 23); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Age) values(24); Query OK, 1 row ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
80 Views
You can use update along with lower() function for this. Let us first create a table −mysql> create table DemoTable ( Id varchar(100), StudentFirstName varchar(20), StudentLastName varchar(20), StudentCountryName varchar(10) ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('STU-101', 'John', 'Smith', 'US'); Query OK, 1 row affected (0.59 sec) mysql> insert into DemoTable values('STU-102', 'John', 'Doe', 'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('STU-103', 'David', 'Miller', 'AUS'); Query OK, 1 row affected (0.19 sec)Following is the query to display all ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
198 Views
To convert string to bitset, use the CONV() method. Let us first create a table −mysql> create table DemoTable ( stringValue BIT(4) ); Query OK, 0 rows affected (3.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(CONV('1110', 2, 10) * 1); Query OK, 1 row affected (0.62 sec) mysql> insert into DemoTable values(b'1011'); Query OK, 1 row affected (0.14 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;Following is the output that displays blank result because the type is bitset −Following is the query ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
132 Views
You can easily add multiple items with only one insert command. The syntax is as follows −insert into yourTableName(yourColumnName1, yourColumnName2, ......N) values(yourValue1, yourValue2, ....N), (yourValue1, yourValue2, ....N), ..........N;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Value1 int, Value2 int, Value3 int ); Query OK, 0 rows affected (0.79 sec)Insert multiple records in the table using insert command −mysql> insert into DemoTable(Value1, Value2, Value3) values(10, 20, 40), (100, 148, 120), (150, 670, 1000), (100000, 200000, 409999); Query OK, 4 rows affected (0.17 sec) Records : 4 Duplicates : ... Read More