- 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
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
2K+ Views
You can use $pull operator to remove the object from an array in MongoDB. To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.removeObjectFromArrayDemo.insertOne( ... { ... ... "StudentName": "John", ... "StudentAcademicProjectDetails": ... [{ ... "StudentProjectId": 101, ... "StudentProjectName": "Pig Dice Game" ... }, ... { ... "StudentProjectId": 110, ... "StudentProjectName": "Library Management System" ... ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
113 Views
MongoDB indexes every value of an array so that you can query for single elements.To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.indexingForArrayElementDemo.insertOne({"StudentFavouriteSubject":["MongoDB", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8acdca6cea1f28b7aa0816") }Display all documents from a collection with the help of find() method. The query is as follows −> db.indexingForArrayElementDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c8acdca6cea1f28b7aa0816"), "StudentFavouriteSubject" : [ "MongoDB", "MySQL" ] }Here is the query by which MongoDB index ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
496 Views
You need to use ALTER TABLE command along with MODIFYThe syntax is as followsALTER TABLE yourTableName MODIFY COLUMN yourColumnName varchar(100) NOT NULL;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table syntaxOfAlterCommandDemo -> ( -> UserId int, -> UserName varchar(30), -> UserAge int, -> UserCityName varchar(50) -> ); Query OK, 0 rows affected (0.51 sec)Let us check the description of the table.The query is as followsmysql> desc syntaxOfAlterCommandDemo;The following is the output+--------------+-------------+------+-----+---------+-------+ | Field | Type ... Read More
![Chandu yadav](https://www.tutorialspoint.com/assets/profiles/22330/profile/60_142811-1519038104.jpg)
188 Views
To replace values in a table, use the CASE statement. To understand the concept, let us create a table. The query to create a table is as followsmysql> create table replaceValueDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(10), -> isGreaterThan18 varchar(10) -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into replaceValueDemo(Name, isGreaterThan18) values('John', 'YES'); Query OK, 1 row affected (0.24 sec) mysql> insert into replaceValueDemo(Name, isGreaterThan18) values('Carol', 'NO'); Query OK, 1 row affected (0.16 sec) ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
161 Views
Let us first create a collection with the document. The query to create a collection with a document is as follows −> db.aggregationFrameworkWithOrMatchDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac3a96cea1f28b7aa080d") } > db.aggregationFrameworkWithOrMatchDemo.insertOne({"StudentFirstName":"Carol", "StudentLastName":"Tayor", "StudentAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac3bc6cea1f28b7aa080e") } > db.aggregationFrameworkWithOrMatchDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac3ce6cea1f28b7aa080f") } > db.aggregationFrameworkWithOrMatchDemo.insertOne({"StudentFirstName":"Bob", "StudentLastName":"Taylor", "StudentAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac3e16cea1f28b7aa0810") } > db.aggregationFrameworkWithOrMatchDemo.insertOne({"StudentFirstName":"Robert", "StudentLastName":"Smith", "StudentAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac3fb6cea1f28b7aa0811") } > db.aggregationFrameworkWithOrMatchDemo.insertOne({"StudentFirstName":"Mike", "StudentLastName":"Miller", ... Read More
![Arjun Thakur](https://www.tutorialspoint.com/assets/profiles/13574/profile/60_74441-1560315595.jpg)
2K+ Views
To retrieve time as HH:MM format, use the DATE_FORMAT() function. To understand the function and retrieve time, let us create a table.The query to create a table is as followsmysql> create table retrieveTimeDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserArrivalTime datetime -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into retrieveTimeDemo(UserArrivalTime) values('2013-01-21 13:45:34'); Query OK, 1 row affected (0.16 sec) mysql> insert into retrieveTimeDemo(UserArrivalTime) values('2014-11-25 11:40:56'); Query OK, 1 row affected (0.11 sec) mysql> insert into retrieveTimeDemo(UserArrivalTime) ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
305 Views
To query condition on comparing 2 fields, use the following syntax −db.yourCollectionName.find( { $where: function() { return this.yourFirstFieldName < this.yourSecondFieldName } } ).pretty();To understand the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.comparingTwoFieldsDemo.insertOne({"StudentName":"John", "StudentAge":21, "StudentMathMarks":99, "StudentPhysicsMarks":98}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac09e6cea1f28b7aa0807") } > db.comparingTwoFieldsDemo.insertOne({"StudentName":"Carol", "StudentAge":22, "StudentMathMarks":79, "StudentPhysicsMarks":89}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac0b46cea1f28b7aa0808") } > db.comparingTwoFieldsDemo.insertOne({"StudentName":"David", "StudentAge":24, "StudentMathMarks":39, "StudentPhysicsMarks":45}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ac0c96cea1f28b7aa0809") } > db.comparingTwoFieldsDemo.insertOne({"StudentName":"Bob", "StudentAge":23, "StudentMathMarks":87, "StudentPhysicsMarks":78}); { "acknowledged" : ... Read More
![Ankith Reddy](https://www.tutorialspoint.com/assets/profiles/22328/profile/60_142162-1519038074.jpg)
6K+ Views
To get the maximum value from three different columns, use the GREATEST() function.The syntax is as followsSELECT GREATEST(yourColumnName1, yourColumnName2, yourColumnName3) AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table MaxOfThreeColumnsDemo -> ( -> First int, -> Second int, -> Third int -> ); Query OK, 0 rows affected (0.73 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into MaxOfThreeColumnsDemo values(30, 90, 60); Query OK, 1 row affected (0.16 sec) mysql> insert into MaxOfThreeColumnsDemo values(100, ... Read More
![George John](https://www.tutorialspoint.com/assets/profiles/13511/profile/60_58410-1512537824.png)
1K+ Views
Restart the MySQL Server with the help of restart command.The syntax is as followsRestartLet us first check the MySQL version.The query is as followsSELECT version();Now, implement the above command in order to restart the MySQL Server.The query is as followsmysql> restart; Query OK, 0 rows affected (0.00 sec)Case 1Now, MySQL Server is being restarted. If you try to perform any query during the restart command, you will get an error.The query is as followsmysql> show databases; ERROR 2013 (HY000): Lost connection to MySQL server during queryCase 2If the MySQL restart process is complete, then a new connection id will be ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
876 Views
You can remove an array element by its index using the following two steps −The first step is as follows −db.yourCollectionName.update({}, {$unset : {"yourArrayFieldName.yourIndexValue" : 1 }});The above syntax will put a null value at the location of ‘yourIndexValue’. After that, you need to pull the null value from array filed to remove from an array element.The second step is as follows −db.yourCollectionName.update({}, {$pull : {"yourArrayFieldName" : null}});To implement the syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.removeArrayElementByItsIndexDemo.insertOne({"InstructorName":"David", "InstructorAge":28, "InstructorSubject":["MongoDB", "MySQL", "Java", "SQL Server", ... Read More