- 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)
462 Views
Let us first create a table −mysql> create table DemoTable2029 -> ( -> Id int, -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.98 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2029 values(1, 'Chris', 'Brown') -> ; Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2029 values(2, 'David', 'Miller'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2029 values(3, 'John', 'Smith'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable2029 values(4, 'John', 'Brown'); Query OK, 1 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
356 Views
Let us first create a table −mysql> create table DemoTable2028 -> ( -> StudentFirstName varchar(20), -> StudentLastName varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)Here is the query to create a stored procedure and insert values (using delimiter correctly) −mysql> delimiter // mysql> create procedure insert_name(in fname varchar(20), in lname varchar(20)) -> begin -> insert into DemoTable2028 values(fname, lname); -> end -> // Query OK, 0 rows affected (0.17 sec) mysql> delimiter ;Call the stored procedure using CALL command −mysql> call insert_name('Chris', 'Brown'); Query OK, 1 row affected (0.17 sec)Display ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
435 Views
For this, you can use $lookup. Let us create a collection with documents −> db.demo446.insert([ ... { "ProductName": "Product1", "ProductPrice": 60 }, ... { "ProductName": "Product2", "ProductPrice": 90 } ... ]) BulkWriteResult({ "writeErrors" : [ ], "writeConcernErrors" : [ ], "nInserted" : 2, "nUpserted" : 0, "nMatched" : 0, "nModified" : 0, "nRemoved" : 0, "upserted" : [ ] })Display all documents from a collection with the help of find() method −> db.demo446.find();This will produce the following output −{ "_id" : ObjectId("5e790766bbc41e36cc3caec3"), "ProductName" : "Product1", "ProductPrice" : 60 } { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
338 Views
Let us first create a table −mysql> create table DemoTable2027 -> ( -> UserId int -> ); Query OK, 0 rows affected (0.65 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2027 values(10); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable2027 values(20); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable2027 values(31); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2027 values(11); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement −mysql> select *from DemoTable2027;This will produce ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
120 Views
To push into an array with MongoDB, use $push. Let us create a collection with documents −> db.demo445.insertOne({"ListOfFriends":["Robert", "Mike", "Sam", "Carol", "David", "Mike"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e78f099bbc41e36cc3caec2") }Display all documents from a collection with the help of find() method −> db.demo445.find().pretty();This will produce the following output −{ "_id" : ObjectId("5e78f099bbc41e36cc3caec2"), "ListOfFriends" : [ "Robert", "Mike", "Sam", "Carol", "David", "Mike" ] }Following is the query to push into an array −> db.demo445.update( ... { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
126 Views
Yes, we can add minutes while inserting values in a table.Let us first create a table. Here, we have a column with VARCHAR records where inmysql> create table DemoTable2026 -> ( -> ArrivalTime varchar(20) -> ); Query OK, 0 rows affected (0.40 sec)Insert some records in the table using insert command. We are first converting the VARCHAR date and then adding minutes −mysql> insert into DemoTable2026 values(date_add(str_to_date('2017-12-01 11:34:45', '%Y-%m-%d %H:%i:%s'), INTERVAL 10 MINUTE)); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable2026 values(date_add(str_to_date('2015-01-31 10:00:00', '%Y-%m-%d %H:%i:%s'), INTERVAL 5 MINUTE)); Query OK, 1 row affected ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
126 Views
For this, use $elemMatch, which is used to query nested objects. Let us create a collection with documents −> db.demo444.insertOne( ... { ... "Information": [{ ... id:1, ... Name:"Chris" ... }] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e78ea87bbc41e36cc3caebf") } > db.demo444.insertOne( ... { ... "Information": [{ ... id:2, ... Name:"David" ... }] ... } ... ); { "acknowledged" : true, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
744 Views
The simplest way to replace records is using MySQL REPLACE() −mysql> create table DemoTable2025 -> ( -> URL text -> ); Query OK, 0 rows affected (0.88 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2025 values('http=//www.facebook.com'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable2025 values('http=//www.google.com'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable2025 values('http=//www.gmail.com'); Query OK, 1 row affected (0.26 sec)Display all records from the table using select statement −mysql> select *from DemoTable2025;This will produce the following output −+-------------------------+ | URL ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
172 Views
The following operations are treated as command operation in MongoDB −1.count 2.findAndModify 3.aggregateFollowing is the example of count in MongoDB −Let us create a collection with documents −> db.demo443.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e78d281bbc41e36cc3caeb9") } > db.demo443.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e78d285bbc41e36cc3caeba") } > db.demo443.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e78d288bbc41e36cc3caebb") }Display all documents from a collection with the help of find() method −> db.demo443.find();This will produce the following output −{ "_id" : ObjectId("5e78d281bbc41e36cc3caeb9"), "Name" : "Chris" } { "_id" : ObjectId("5e78d285bbc41e36cc3caeba"), "Name" : "Bob" } { "_id" : ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
675 Views
For this, use GROUP_CONCAT(). Let us first create a table −mysql> create table DemoTable2024 -> ( -> SubjectName varchar(20), -> StudentName varchar(20) -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command −mysql> insert into DemoTable2024 values('MySQL', 'Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable2024 values('MySQL', 'David'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable2024 values('MongoDB', 'Bob'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable2024 values('Java', 'Sam'); Query OK, 1 row affected (0.18 sec) mysql> ... Read More