- 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
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
1K+ Views
To select dates in 30-day range, you can use arithmetic operation - with interval.The syntax is as follows −select *from yourTableName where yourDateColumnName > NOW() - INTERVAL 30 DAY and yourDateColumnName < NOW() + INTERVAL 30 DAY;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table selectDatesDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.77 sec)Now you can insert some records in the table using insert command. The query is as ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
96 Views
Let us first create a demo table −mysql> create table selectPerson -> ( -> PersonId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> PersonName varchar(20), -> PersonFavouriteFruit varchar(60) -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into selectPerson(PersonName, PersonFavouriteFruit) values('John', 'Banana'); Query OK, 1 row affected (0.14 sec) mysql> insert into selectPerson(PersonName, PersonFavouriteFruit) values('John', 'Blackberry'); Query OK, 1 row affected (0.12 sec) mysql> insert into selectPerson(PersonName, PersonFavouriteFruit) values('John', 'Blueberry'); Query OK, 1 row affected (0.12 sec) mysql> insert into selectPerson(PersonName, ... Read More
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
43 Views
To test, use the sleep() function.Case 1 −The syntax is as follows −SELECT yourColumnName+sleep(yourIntegerValue) FROM yourTableName GROUP BY yourColumnName+sleep(yourIntegerValue);;Case 2 − You can use another syntax which is as follows −SELECT yourColumnName+sleep(yourIntegerValue) As anyAliasName FROM yourTableName GROUP BY yourAliasName;To understand the above syntaxes, let us create a table. The query to create a table is as follows −mysql> create table sleepDemo -> ( -> value int -> ); Query OK, 0 rows affected (1.25 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into sleepDemo values(40); Query OK, 1 row ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
1K+ Views
No, you cannot give the same name for view and table in MySQL.Let us first create a demo table −mysql> create table view_Table_Demo -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.80 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into view_Table_Demo values(100, 'Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into view_Table_Demo values(101, 'Mike'); Query OK, 1 row affected (0.20 sec) mysql> insert into view_Table_Demo values(102, 'Sam'); Query OK, 1 row affected (0.14 sec)Display all ... Read More
![Samual Sam](https://www.tutorialspoint.com/assets/profiles/13514/profile/60_83486-1512649303.jpg)
672 Views
You can use SET command, but SET OPTIOn deprecated. Therefore, use SET SQL_SELECT_LIMIT.The syntax is as follows −SET SQL_SELECT_LIMIT=yourIntegerValue;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table MySQLSelectDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.99 sec)Insert some records in the table using insert command. The query is as follows −mysql> INSERT INTO MySQLSelectDemo VALUES(), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), (), ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
850 Views
To get the highest value of a column in MongoDB, you can use sort() along with limit(1). The syntax is as follows −db.yourCollectionName.find().sort({"yourFieldName":-1}).limit(1);To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.gettingHighestValueDemo.insertOne({"Value":1029}); { "acknowledged" : true, "insertedId" : ObjectId("5c900b885705caea966c5574") } > db.gettingHighestValueDemo.insertOne({"Value":3029}); { "acknowledged" : true, "insertedId" : ObjectId("5c900b8d5705caea966c5575") } > db.gettingHighestValueDemo.insertOne({"Value":1092}); { "acknowledged" : true, "insertedId" : ObjectId("5c900b925705caea966c5576") } > db.gettingHighestValueDemo.insertOne({"Value":18484}); { "acknowledged" : true, "insertedId" : ObjectId("5c900b955705caea966c5577") } > db.gettingHighestValueDemo.insertOne({"Value":37474}); { "acknowledged" ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
121 Views
You can use $where operator for this. 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.queryInSameDocumentsDemo.insertOne({"StudentDetails":{"StudentName":"John"}, "NewStudentDetails":{"StudentName":"Carol"}}); { "acknowledged" : true, "insertedId" : ObjectId("5c90096ed3c9d04998abf017") } > db.queryInSameDocumentsDemo.insertOne({"StudentDetails":{"StudentName":"Bob"}, "NewStudentDetails":{"StudentName":"Bob"}}); { "acknowledged" : true, "insertedId" : ObjectId("5c900a435705caea966c5573") }Display all documents from a collection with the help of find() method. The query is as follows −> db.queryInSameDocumentsDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c90096ed3c9d04998abf017"), "StudentDetails" : { "StudentName" : "John" }, "NewStudentDetails" : { ... Read More
![Smita Kapse](https://www.tutorialspoint.com/assets/profiles/13597/profile/60_103706-1512718957.jpg)
1K+ Views
The syntax is as follows for this −db.yourCollectionName.update({ }, { $set: { "yourOuterFieldName.yourInnerFieldName": "yourValue" } });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.updateNestedValueDemo.insertOne({"CustomerName":"Chris", ... "CustomerDetails":{"CustomerAge":25, "CustomerCompanyName":"Google", "CustomerCityName":"US"}}); { "acknowledged" : true, "insertedId" : ObjectId("5c8fccc4d3c9d04998abf015") }Display all documents from a collection with the help of find() method. The query is as follows −> db.updateNestedValueDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c8fccc4d3c9d04998abf015"), "CustomerName" : "Chris", "CustomerDetails" : { "CustomerAge" : 25, ... Read More
![Nishtha Thakur](https://www.tutorialspoint.com/assets/profiles/13598/profile/60_104893-1512719058.jpg)
1K+ Views
To get the list of all values of certain fields in MongoDB, you can use distinct(). The syntax is as follows −db.yourCollectionName.distinct( "yourFieldName");To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[10, 20, 30]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8fc89ed3c9d04998abf011") } > db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[40, 50, 60]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8fc8abd3c9d04998abf012") } > db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[10, 20, 30]}); { "acknowledged" : true, "insertedId" : ObjectId("5c8fc8d7d3c9d04998abf013") } > db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[40, 50, 70]}); { "acknowledged" : true, "insertedId" ... Read More
![Anvi Jain](https://www.tutorialspoint.com/assets/profiles/13591/profile/60_98631-1512716973.jpg)
366 Views
To create nested index in MongoDB, you can use createIndex() or ensureIndex(). The syntax is as follows −db.yourCollectionName.createIndex({"yourOuterFieldName.yourInnerFieldName.yourSecondInnerFieldName": 1});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.nestedIndexDemo.insertOne( ... { ... ... "CustomerId":101, ... "CustomerDetails": ... { ... "CustomerListDetails": ... { ... "CustomerName":"Larry", ... "CustomerProjectName": "Project-1", ... Read More