- 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
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
132 Views
Let us first create a collection with documents -> db.removingAnArrayElementDemo.insertOne({"UserMessage":["Hi", "Hello", "Bye"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef97bdef71edecf6a1f6a4") }Display all documents from a collection with the help of find() method -> db.removingAnArrayElementDemo.find().pretty();Output{ "_id" : ObjectId("5cef97bdef71edecf6a1f6a4"), "UserMessage" : [ "Hi", "Hello", "Bye" ] }Following is the query to remove an array element from MongoDB -> db.removingAnArrayElementDemo.update( {_id:ObjectId("5cef97bdef71edecf6a1f6a4")}, { "$pull": { "UserMessage": "Hello" } } ); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })Let us check the document once again:> db.removingAnArrayElementDemo.find().pretty();Output{ ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
66 Views
Let us first create a collection with documents -> db.operatorDemo.insertOne({"StudentSubject":["MongoDB", "MySQL", "Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef94eaef71edecf6a1f6a2") } > db.operatorDemo.insertOne({"StudentSubject":["Java", "C", "C++"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef94faef71edecf6a1f6a3") }Display all documents from a collection with the help of find() method -> db.operatorDemo.find().pretty();Output{ "_id" : ObjectId("5cef94eaef71edecf6a1f6a2"), "StudentSubject" : [ "MongoDB", "MySQL", "Java" ] } { "_id" : ObjectId("5cef94faef71edecf6a1f6a3"), "StudentSubject" : [ "Java", "C", "C++" ] }Following is the query for ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
64 Views
Let us first create a table −mysql> create table DemoTable1 ( value int ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command −mysql> insert into DemoTable1 values(10); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable1;Output+-------+ | value | +-------+ | 10 | +-------+ 1 row in set (0.00 sec)Following is the query to create second table −mysql> create table DemoTable2 ( value1 int ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
To set all the values in a field to 0, use the update command −update yourTableName set yourColumnName=0;Let us first create a table −mysql> create table DemoTable ( Number int ); Query OK, 0 rows affected (0.64 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(4757); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values(48474); Query OK, 1 row affected (0.26 sec) mysql> insert into DemoTable values(35465); Query OK, 1 row affected (0.16 sec)Display all records from ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
463 Views
Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(20) ); Query OK, 0 rows affected (1.23 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(StudentName) values('John'); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(StudentName) values('Carol'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(StudentName) values('David'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(StudentName) values('Bob'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(StudentName) values('Chris'); Query OK, 1 row affected (0.12 sec) ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
87 Views
To get the last days of all the months, use the LAST_DAY() function from MySQL −SELECT LAST_DAY(yourColumnName) from yourTableName;Let us first create a table −mysql> create table DemoTable ( ShippingDate date ); Query OK, 0 rows affected (0.69 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('2019-01-12'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2019-02-01'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('2019-03-04'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-04-21'); Query OK, 1 row affected (0.14 sec)Display all records ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
680 Views
Use the concept of DATE_SUB(). Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, ArrivalDate datetime ); Query OK, 0 rows affected (1.02 sec)Note: Let’s say the current date is 2019-06-08Insert some records in the table using insert command −mysql> insert into DemoTable(ArrivalDate) values('2019-05-15'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-06-08'); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-05-20'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(ArrivalDate) values('2019-05-12'); Query OK, 1 row affected (0.12 sec)Display ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
1K+ Views
To delete all rows except a single specific row, try the below syntax −delete from yourTableName where yourColumnName!=yourValue;Let us first create a table −mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Subject varchar(100) ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject) values('MySQL'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject) values('MongoDB'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(Subject) values('Java'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
346 Views
You can use CONCAT() for this. The syntax is as follows −insert into DemoTable values(concat(curdate(), ' yourSpecificTime’));Let us first create a table −mysql> create table DemoTable ( ArrivalDate datetime ); Query OK, 0 rows affected (1.06 sec)Insert some records in the table using insert command. We are adding the current date and time −mysql> insert into DemoTable values(concat(curdate(), ' 10:20:05')); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values(concat(curdate(), ' 12:05:00')); Query OK, 1 row affected (0.17 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+---------------------+ | ArrivalDate ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
68 Views
You can use delete command −delete from yourTableName where yourColumnName='\\';Let us first create a table −mysql> create table DemoTable ( FolderName varchar(100) ); Query OK, 0 rows affected (0.67 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values("????"); Query OK, 1 row affected (0.44 sec) mysql> insert into DemoTable values("\\"); Query OK, 1 row affected (0.13 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+------------+ | FolderName | +------------+ | ???? | | \ ... Read More