
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

714 Views
You can use row_count() at the end for this. Let us first create a table −mysql> create table rowAfftectedByDeleteDemo -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(20) -> ); Query OK, 0 rows affected (0.86 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Carol'); Query OK, 1 row affected (0.10 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Bob'); Query OK, 1 row affected (0.09 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Sam'); Query ... Read More

987 Views
Yes, we can. In order to store CSS color value, you can use CHAR(6) without # symbol for hexadecimal. Let us see an example and create a tablemysql> create table storeCSSColorDemo -> ( -> CSSValue char(6) -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command. The records here are individual color values in hexadecimal, for which we have used char(6)mysql> insert into storeCSSColorDemo values('FF0000'); Query OK, 1 row affected (0.13 sec) mysql> insert into storeCSSColorDemo values('FFA500'); Query OK, 1 row affected (0.86 sec) ... Read More

490 Views
Let us first create a new table and understand the concept in continuationmysql> create table StoredProcedureInsertDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserAge int -> ); Query OK, 0 rows affected (0.63 sec)Here is the query to create a stored procedure to insert data in to the tablemysql> DELIMITER // mysql> create procedure procedure_InsertIntoTable(IN FirstName VARCHAR(100), IN Age INT) -> BEGIN -> insert into StoredProcedureInsertDemo(UserName, UserAge) values (FirstName, Age); -> END -> // Query OK, 0 rows affected (0.34 sec) mysql> DELIMITER ;Call ... Read More

505 Views
In order to delete the collection which has some special characters like _ or -, you need to use the following syntax −db.getCollection("yourCollectionName").drop();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.createCollection("_personalInformation"); { "ok" : 1 } > db.getCollection('_personalInformation').insertOne({"ClientName":"Chris", "ClientCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9158bb4afe5c1d2279d6b2") } > db.getCollection('_personalInformation').insertOne({"ClientName":"Mike", "ClientCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9158c84afe5c1d2279d6b3") } > db.getCollection('_personalInformation').insertOne({"ClientName":"David", "ClientCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9158d54afe5c1d2279d6b4") }Display all documents from a collection with the ... Read More

215 Views
You can use RAND() method for this. To retrieve a random row, use the following syntaxSELECT *FROM yourTableName ORDER BY RAND() LIMIT yourIntegerNumber;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table gettingRandomRow -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(100) -> ); Query OK, 0 rows affected (0.45 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into gettingRandomRow(CustomerName) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into gettingRandomRow(CustomerName) values('Robert'); ... Read More

637 Views
To remove the _id element, you can use the following syntax −db.yourCollectionName.find({}, {'_id': false}).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.removingidElementDemo.insertOne({"UserName":"John", ... "UserAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c9153fd4afe5c1d2279d6ad") } > db.removingidElementDemo.insertOne({"UserName":"Carol", "UserAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c9154084afe5c1d2279d6ae") } > db.removingidElementDemo.insertOne({"UserName":"David", "UserAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c9154154afe5c1d2279d6af") } > db.removingidElementDemo.insertOne({"UserName":"Mike", "UserAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c9154204afe5c1d2279d6b0") } > db.removingidElementDemo.insertOne({"UserName":"Chris", "UserAge":20}); { "acknowledged" : true, ... Read More

816 Views
You can use IF() to GROUP BY multiple columns. To understand the concept, let us create a table. The query to create a table is as followsmysql> create table MultipleGroupByDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerId int, -> ProductName varchar(100) -> ); Query OK, 0 rows affected (0.59 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into MultipleGroupByDemo(CustomerId, ProductName) values(1000, 'Product-1'); Query OK, 1 row affected (0.20 sec) mysql> insert into MultipleGroupByDemo(CustomerId, ProductName) values(1001, 'Product-2'); Query OK, 1 row affected (0.18 ... Read More

527 Views
There is no in-built function to count a number of keys in a document. In order to count a number of keys, you need to write some code.Let us create a collection with a document. The query to create a collection with a document is as follows −> db.numberofKeysInADocumentDemo.insertOne({ "UserName":"John", "UserAge":21, "UserEmailId":"john12@gmail.com", "UserCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9132584afe5c1d2279d6ac") }Display all documents from a collection with the help of find() method. The query is as follows −> db.numberofKeysInADocumentDemo.find().pretty();The following is the output −{ "_id" : ObjectId("5c9132584afe5c1d2279d6ac"), "UserName" : "John", "UserAge" : 21, ... Read More

2K+ Views
To sum columns across multiple tables, use UNION ALL. To understand the concept, let us create first table. The query to create first table is as followsmysql> create table Products1 -> ( -> ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ProductName varchar(20), -> ProductPrice int -> ); Query OK, 0 rows affected (0.50 sec)Insert some records in the first table using insert command. The query is as follows −mysql> insert into Products1(ProductName, ProductPrice) values('Product-1', 100); Query OK, 1 row affected (0.22 sec) mysql> insert into Products1(ProductName, ProductPrice) values('Product-2', 200); Query OK, 1 row affected ... Read More

343 Views
You can use “$regex” operator to implement the equivalent of SQL ‘like’ in MongoDB. To implement it, let us create a collection with a document. The query to create a collection with a document is as follows −> db.sqlLikeDemo.insertOne({"UserName":"John Smith", "UserAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c912e124afe5c1d2279d6a5") } > db.sqlLikeDemo.insertOne({"UserName":"John Doe", "UserAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c912e264afe5c1d2279d6a6") } > db.sqlLikeDemo.insertOne({"UserName":"Chris Williams", "UserAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c912e404afe5c1d2279d6a7") } > db.sqlLikeDemo.insertOne({"UserName":"Robert Taylor", "UserAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c912e4d4afe5c1d2279d6a8") } > db.sqlLikeDemo.insertOne({"UserName":"John Brown", "UserAge":27}); { "acknowledged" ... Read More