
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 6705 Articles for Database

117 Views
To implement AND condition, the syntax is as follows −select *from yourTableName where yourColumnName1 = yourValue1 AND yourColumnName2 = yourValue2;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table MySQLANDConditionDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100), -> Age int -> ); Query OK, 0 rows affected (0.80 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into MySQLANDConditionDemo(Name, Age) values('Larry', 23); Query OK, 1 row affected (0.11 sec) mysql> ... Read More

467 Views
You can easily insert a row into a table that has only a single auto increment column. The syntax is as follows −insert into yourTableName set yourColumnName =NULL;You can use the below syntax −insert into yourTableName values(NULL);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table singleAutoIncrementColumnDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.62 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into singleAutoIncrementColumnDemo set UserId ... Read More

195 Views
You can use GLOBAL variable as shown below −SET global innodb_stats_on_metadata =0;After including the above syntax, the INFORMATION_SCHEMA.key_column_usage will take less time and that would improve the performance.The query is as follows −mysql> set global innodb_stats_on_metadata =0; Query OK, 0 rows affected (0.00 sec) mysql> SELECT REFERENCED_TABLE_NAME,TABLE_NAME,COLUMN_NAME,CONSTRAINT_SCHEMA -> FROM INFORMATION_SCHEMA.key_column_usage;The following is the output −It returns 674 rows in 0.28 seconds.

336 Views
You can use $unset as well as $pull operator with an update to delete the nth element of an array.Let us create a collection with a document. The query to create a collection with a document is as follows −> db.getNThElementDemo.insertOne({"UserName":"John", "UserAge":23, "ListOfFriends":["Carol", "Sam", "Mike", "Bob"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c94ee7516f542d757e2b43e") } > db.getNThElementDemo.insertOne({"UserName":"David", "UserAge":21, "ListOfFriends":["Chris", "Robert"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c94eeaa16f542d757e2b43f") }Display all documents from a collection with the help of find() method. The query is as follows −> db.getNThElementDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c94ee7516f542d757e2b43e"), "UserName" ... Read More

232 Views
To identify the last document from MongoDB find() result set, you can use sort() in descending order. The syntax is as follows −db.yourCollectionName.find().sort( { _id : -1 } ).limit(1).pretty();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.identifyLastDocuementDemo.insertOne({"UserName":"Larry", "UserAge":24, "UserCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c94a2ff4cf1f7a64fa4df57") } > db.identifyLastDocuementDemo.insertOne({"UserName":"Chris", "UserAge":21, "UserCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c94a3094cf1f7a64fa4df58") } > db.identifyLastDocuementDemo.insertOne({"UserName":"David", "UserAge":25, "UserCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c94a3174cf1f7a64fa4df59") } > db.identifyLastDocuementDemo.insertOne({"UserName":"Sam", "UserAge":26, "UserCountryName":"US"}); { ... Read More

670 Views
To ignore the year with date range, use the DATE_FORMAT() with the between clause. Let us first create a demo table. The query to create a table is as follows −mysql> create table igonreYearDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ShippingDate date -> ); Query OK, 0 rows affected (0.75 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into igonreYearDemo(ShippingDate) values('2016-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into igonreYearDemo(ShippingDate) values('2018-01-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into ... Read More

2K+ Views
In order to check the current configuration of MongoDB, you can use getCmdLineOpts. The query is as follows −> db._adminCommand( {getCmdLineOpts: 1});The following is the output −{ "argv" : [ "mongod" ], "parsed" : { }, "ok" : 1 }In order to check live settings, you can use the below query −> db._adminCommand({getParameter:"*"});The following is the output &minus{ "AsyncRequestsSenderUseBaton" : true, "KeysRotationIntervalSec" : 7776000, "ShardingTaskExecutorPoolHostTimeoutMS" : 300000, "ShardingTaskExecutorPoolMaxConnecting" : 2, "ShardingTaskExecutorPoolMaxSize" : -1, "ShardingTaskExecutorPoolMinSize" : 1, "ShardingTaskExecutorPoolRefreshRequirementMS" : 60000, "ShardingTaskExecutorPoolRefreshTimeoutMS" : 20000, "TransactionRecordMinimumLifetimeMinutes" : 30, "adaptiveServiceExecutorIdlePctThreshold" : 60, "adaptiveServiceExecutorMaxQueueLatencyMicros" ... Read More

170 Views
To get the number of days between current date and date field, the syntax is as follows −SELECT DATEDIFF(CURDATE(), STR_TO_DATE(yourColumnName, '%d-%m-%Y')) AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DateDifferenceDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ArrivalDate varchar(100) -> ); Query OK, 0 rows affected (0.55 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into DateDifferenceDemo(ArrivalDate) values('12-10-2011'); Query OK, 1 row affected (0.14 sec) mysql> insert ... Read More

382 Views
To reserve MySQL auto-incremented IDs, the syntax is as follows −START TRANSACTION; insert into yourTableName values(), (), (), (); ROLLBACK; SELECT LAST_INSERT_ID() INTO @anyVariableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table reservingAutoIncrementDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command. The query is as follows −mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> insert into reservingAutoIncrementDemo values(), (), (), (); Query ... Read More

284 Views
You can achieve pagination with the help of limit() and skip() 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.paginationDemo.insertOne({"CustomerName":"Chris", "CustomerAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5c949de44cf1f7a64fa4df52") } > db.paginationDemo.insertOne({"CustomerName":"Robert", "CustomerAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c949df14cf1f7a64fa4df53") } > db.paginationDemo.insertOne({"CustomerName":"David", "CustomerAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c949dfc4cf1f7a64fa4df54") } > db.paginationDemo.insertOne({"CustomerName":"Carol", "CustomerAge":28}); { "acknowledged" : true, "insertedId" : ObjectId("5c949e3e4cf1f7a64fa4df55") } > db.paginationDemo.insertOne({"CustomerName":"Bob", "CustomerAge":29}); { "acknowledged" : true, "insertedId" : ObjectId("5c949e474cf1f7a64fa4df56") ... Read More