- 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
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
824 Views
For this, use SELECT CASE. Let us first create a table −mysql> create table DemoTable -> ( -> Num1 int, -> Num2 int -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 30); Query OK, 1 row affected (0.11 sec)Display all records from the table using select statement −mysql> select *from DemoTable;OutputThis will produce the following output −+------+------+ | Num1 | Num2 | +------+------+ | 10 | 30 | +------+------+ 1 row in set (0.00 sec)Following is the query to store ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
101 Views
Let us first see the syntax of IF NOT IN in MySQL −if(yourVariableName NOT IN (yourValue1, yourValue2, ........N) ) then statement1 else statement2 endif Let us implement the above syntax to use IF NOT IN −mysql> DELIMITER // mysql> CREATE PROCEDURE IF_NOT_INDemo(IN value int) -> BEGIN -> if(value NOT IN (10, 20, 30) ) then -> select "Value Not Found"; -> else -> select "Value Found"; -> end if; -> END ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
87 Views
Let us first create a table −mysql> create table DemoTable -> ( -> UserId int -> ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.09 sec) ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
2K+ Views
For this, you can use ORDER BY DESC LIMIT. Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('John'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Name) values('Sam'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Name) values('Carol'); Query OK, 1 row affected (0.34 sec)Display all records from the table using select statement −mysql> ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
232 Views
Yes, the AUTO_INCREMENT in MySQL will be signed (Positive and Negative Value both) by default.Let us first create a table −mysql> create table DemoTable -> ( -> MyNumber int AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command. Here, we have set negative values as well for AUTO_INCREMENT column −mysql> insert into DemoTable values() ; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(-100); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(-300); Query OK, 1 row affected ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
1K+ Views
To order an alphanumeric column with values like “100X, “2Z”, etc. use the ORDER BY. Let us first create a table −mysql> create table DemoTable -> ( -> StudentId varchar(100) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2X'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('100Y'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values('100X'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2Z'); Query OK, 1 row affected (0.14 sec) mysql> ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
3K+ Views
Let us first create a table −mysql> create table DemoTable -> ( -> NumberOfItems int, -> Amount int -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(4, 902); Query OK, 1 row affected (0.45 sec) mysql> insert into DemoTable values(5, 1000); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(3, 80); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+---------------+--------+ | NumberOfItems | Amount | +---------------+--------+ | ... Read More
![Rama Giri](https://www.tutorialspoint.com/assets/profiles/13881/profile/60_68188-1512710896.jpg)
452 Views
Let us first create a table −mysql> create table DemoTable1 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.76 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1(Name) values('Chris'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1(Name) values('Robert'); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;Output+----+--------+ | Id | Name | +----+--------+ | 1 | Chris | | 2 | Robert | +----+--------+ 2 ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
330 Views
For this, you can use aggregate function COUNT(*). Let us first create a table in let’s say database “web” −mysql> create table DemoTable1 -> ( -> Value int -> ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable1 values(20); Query OK, 1 row affected (0.15 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;OutputThis will produce the following output −+-------+ | Value | +-------+ | 10 | | ... Read More
![Kumar Varma](https://www.tutorialspoint.com/assets/profiles/13883/profile/60_73481-1512711460.jpg)
504 Views
Following is the syntax −update yourTableName set yourColumnName1= yourValue where yourColumnName2=yourValue order by yourColumnName2 DESC LIMIT 1;Let us first create a table −mysql> create table DemoTable -> ( -> Id int, -> Name varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(1, 'John'); Query OK, 1 row affected (0.41 sec) mysql> insert into DemoTable values(2, 'Chris'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values(2, 'Robert'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More