- 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
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
85 Views
To order, use ORDER BY and to fetch only the 2nd ordered record, use MySQL LIMIT and set offset as well. Let us first create a −mysql> create table DemoTable1417 -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(20), -> ShippingDate date -> ); Query OK, 0 rows affected (1.10 sec)Insert some records in the table using insert −mysql> insert into DemoTable1417(CustomerName, ShippingDate) values('Chris', '2019-01-21'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1417(CustomerName, ShippingDate) values('David', '2018-12-01'); Query OK, 1 row affected (0.55 sec) mysql> insert into DemoTable1417(CustomerName, ShippingDate) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
127 Views
For this, you can use SUBSTRING_INDEX(). Let us first create a −mysql> create table DemoTable1416 -> ( -> StudentCode varchar(100) -> ); Query OK, 0 rows affected (1.56 sec)Insert some records in the table using insert −mysql> insert into DemoTable1416 values('101/John/Smith'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1416 values('901/Carol/Taylor'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1416 values('400/David/Miller'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select −mysql> select * from DemoTable1416;This will produce the following output −+------------------+ | StudentCode | +------------------+ | ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
For this, use EXTRACT(), that would allow you to extract specific month records. For example, to add all the prices in January (irrespective of the year).Let us first create a −mysql> create table DemoTable1415 -> ( -> ProductPurchaseDate date, -> ProductPrice int -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert −mysql> insert into DemoTable1415 values('2019-01-12', 560); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1415 values('2018-01-14', 1060); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1415 values('2017-03-21', 780); Query OK, 1 row affected (0.11 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
156 Views
For this, use MySQL MIN(). Let us first create a −mysql> create table DemoTable1414 -> ( -> BookTitle varchar(40), -> BookPrice int -> ); Query OK, 0 rows affected (0.82 sec)Insert some records in the table using insert −mysql> insert into DemoTable1414 values('Deep dive using java', 560); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('C++ in depth', 360); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Data structure in C', 590); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1414 values('Algorithm in C++', 1090); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
219 Views
The fastest and easiest way is to use the MySQL BETWEEN keyword. Let us first create a −mysql> create table DemoTable1413 -> ( -> EmployeeName varchar(20), -> EmployeeJoiningDate datetime -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert −mysql> insert into DemoTable1413 values('Chris', '2018-09-28 11 :10 :50'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable1413 values('David', '2019-09-28 11:10:50'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1413 values('Mike', '2019-09-29 12:40:00'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1413 values('Carol', '2019-09-28 12:06:10'); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
269 Views
For this, use Regular Expression in MySQL as in the below syntax −select * from yourTableName where yourColumnName regexp '^[^ ]+[ ]+[^ ]+$';The above query will work when the two words are separated by a space. Let us first create a −mysql> create table DemoTable1412 -> ( -> Name varchar(40) -> ); Query OK, 0 rows affected (0.52 sec)Insert some records in the table using insert −mysql> insert into DemoTable1412 values('John Adam Carol'); Query OK, 1 row affected (0.09 sec) mysql> insert into DemoTable1412 values('Mike Sam'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1412 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
177 Views
For this, use FIND_IN_SET() in MySQL and use the value from a custom variable. Let us first create a −mysql> create table DemoTable1411 -> ( -> Value int -> ) -> ; Query OK, 0 rows affected (0.50 sec)Insert some records in the table using insert −mysql> insert into DemoTable1411 values(10); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1411 values(50); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1411 values(60); Query OK, 1 row affected (0.08 sec)Display all records from the table using select −mysql> select * from DemoTable1411;This will produce ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To mask data fields, use CONCAT() along with REPEAT(). Here, we will mask data fields with #. Let us first create a −mysql> create table DemoTable1410 -> ( -> Password varchar(80) -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1410 values('John12345678'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable1410 values('Carol_897'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1410 values('David_5647383'); Query OK, 1 row affected (0.17 sec)Display all records from the table using select −mysql> select * from DemoTable1410;This will produce ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
71 Views
For this, let us see an example and first create a −mysql> create table DemoTable1409 -> ( -> FirstName varchar(20), -> UNIQUE KEY UN_FirstName(FirstName) -> ); Query OK, 0 rows affected (0.79 sec)Following is the query to add duplicate varchar −mysql> alter table DemoTable1409 drop index UN_FirstName; Query OK, 0 rows affected (0.40 sec) Records: 0 Duplicates: 0 Warnings: 0Insert some records in the table using insert −mysql> insert into DemoTable1409 values('Chris'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1409 values('Chris'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1409 values('David'); ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
736 Views
Let us first create a −mysql> create table DemoTable1407 -> ( -> Name text -> ); Query OK, 0 rows affected (0.51 sec)Insert some records in the table using insert −mysql> insert into DemoTable1407 values('John, Bob'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1407 values('Carol, David, Adam'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1407 values('Mike, Sam, Chris'); Query OK, 1 row affected (0.19 sec)Display all records from the table using select −mysql> select * from DemoTable1407;This will produce the following output −+------------------+ | Name ... Read More