- 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
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
97 Views
Let us first create a collection with documents −> db.matchingFirstItemInTheArrayDemo.insertOne( { "ClientDetails": [ { "ClientName": "Larry", "ClientAge":28 } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a5d26d78f205348bc636") } > db.matchingFirstItemInTheArrayDemo.insertOne( { "ClientDetails": [ { "ClientName": "Chris", "ClientAge":56, } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a5f56d78f205348bc637") } > db.matchingFirstItemInTheArrayDemo.insertOne( ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
To remove last char if it is a specific character then use SUBSTRING(). Let us first create a table −mysql> create table DemoTable ( SubjectName varchar(100) ); Query OK, 0 rows affected (0.47 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('MySQL'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('MongoDB?'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('Java?'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('C'); Query OK, 1 row affected (0.16 sec)Display all records from the table using select ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
593 Views
You can use DATE_ADD() function with where clause for this. Let us first create a table −mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.54 sec)Note : The current date and time is as follows, we found using NOW() −mysql> select now(); +-----------------------+ | now() | +-----------------------+ | 2019-06-04 20 :43 :57 | +-----------------------+ 1 row in set (0.00 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-06-16'); Query OK, 1 ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
640 Views
Let us first create a collection with documents −> db.excludeIdDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd701a56d78f205348bc632") } > db.excludeIdDemo.insertOne({"StudentFirstName":"Robert", "StudentAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5cd701af6d78f205348bc633") } > db.excludeIdDemo.insertOne({"StudentFirstName":"Chris", "StudentAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5cd701b86d78f205348bc634") }Following is the query to display all documents from a collection with the help of find() method −> db.excludeIdDemo.find();This will produce the following output −{ "_id" : ObjectId("5cd701a56d78f205348bc632"), "StudentFirstName" : "John", "StudentAge" : 21 } { "_id" : ObjectId("5cd701af6d78f205348bc633"), "StudentFirstName" : "Robert", "StudentAge" : 20 } { "_id" : ObjectId("5cd701b86d78f205348bc634"), "StudentFirstName" : "Chris", "StudentAge" ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
110 Views
Use BETWEEN clause to search between columns. Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Score1 int, Score2 int ); Query OK, 0 rows affected (0.78 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Score1, Score2) values(45, 65); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable(Score1, Score2) values(450, 680); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable(Score1, Score2) values(800, 900); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
275 Views
To concatenate fields, use the $concat operator. Let us first create a collection with documents −>db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ebf46d78f205348bc62e") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ebfc6d78f205348bc62f") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ec376d78f205348bc630") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Sam", "StudentLastName":"Williams"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ec436d78f205348bc631") }Following is the query to display all documents from a collection with the help of find() method −> db.concatenateFieldsDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd6ebf46d78f205348bc62e"), "StudentFirstName" : "Adam", "StudentLastName" : "Smith" } ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
504 Views
To concatenate two tables, UNION ALL in MySQL. Let us create a table −mysql> create table DemoTable1 ( Id int, FirstName varchar(20) ); Query OK, 0 rows affected (1.52 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10, 'John'); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1 values(20, 'Carol'); Query OK, 1 row affected (0.28 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;Output+------+-----------+ | Id | FirstName | +------+-----------+ | 10 | John | ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
174 Views
Let us first create a collection with documents −> db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[89, 43, 32, 45]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9e9f9b50a6c6dd317adb3") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[32, 33, 34, 40]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9ea13b50a6c6dd317adb4") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[45, 56, 66, 69]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9ea25b50a6c6dd317adb5") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[46, 66, 77, 88]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9ea3cb50a6c6dd317adb6") }Following is the query to display all documents from a collection with the help of find() method −> db.arrayElementsNotGreaterThanDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd9e9f9b50a6c6dd317adb3"), "Scores" : [ ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
78 Views
To view the indexes, you can use SHOW command.Following is the syntax −show index from yourTableName;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName varchar(20), LastName varchar(20) ); Query OK, 0 rows affected (0.46 sec)Following is the query to create an index −mysql> create index id_FirstName on DemoTable(Id, FirstName); Query OK, 0 rows affected (0.52 sec) Records : 0 Duplicates : 0 Warnings : 0Following is the query to view the indexes I have set up in MySQL −mysql> show index from DemoTable;This will produce ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
1K+ Views
To work with multiple AND conditions in MySQL, following is the syntax −select *from yourTableName where yourColumnName1=yourValue1 and yourColumnName2=yourValue2 and yourColumnName3=yourValue3;Let us first create a table −mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20), StudentAge int, StudentCountryName varchar(40) ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName, StudentAge, StudentCountryName) values('John', 23, 'US'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable(StudentName, StudentAge, StudentCountryName) values('Carol', 21, 'UK'); Query OK, 1 row affected (0.15 sec) mysql> insert ... Read More