Found 6705 Articles for Database

What does a “set+0” in a MySQL statement do?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

115 Views

The set+0 converts the set value to integer. Let us see an example by creating a table −mysql> create table SetZeroDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> TechnicalSkills set('C', 'Spring Framework /Hibernate', 'Python', 'Django Framework', 'Core Java') NOT NULL    -> ); Query OK, 0 rows affected (0.56 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into SetZeroDemo(TechnicalSkills) -> values('C, Spring Framework /Hibernate, Python, Django Framework, Core Java'); Query OK, 1 row affected (0.20 sec)Display all records from the table using select statement. The ... Read More

How to implement MongoDB $or query?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

167 Views

The syntax is as follows for the $or query in MongoDB −db.yourCollectionName.find({ $or : [ { "yourFieldName" : "yourValue1" }, {"yourFieldName":"yourValue2"}, ...........N ] } ).pretty();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.orDemo.insertOne({"UserName":"Larry", "UserAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9491fd4cf1f7a64fa4df4c") } > db.orDemo.insertOne({"UserName":"David", "UserAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9492074cf1f7a64fa4df4d") } > db.orDemo.insertOne({"UserName":"Mike", "UserAge":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c94920e4cf1f7a64fa4df4e") } > db.orDemo.insertOne({"UserName":"Sam", "UserAge":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9492144cf1f7a64fa4df4f") } ... Read More

How to update all documents in MongoDB?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

837 Views

You can use updateMany() to update documents. Let us create a collection with a document. The query to create a collection with a document is as follows −> db.updateManyDocumentsDemo.insertOne({"StudentName":"John", "StudentLastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948edd4cf1f7a64fa4df48") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"John", "StudentLastName":"Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948ee64cf1f7a64fa4df49") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"Carol", "StudentLastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948ef14cf1f7a64fa4df4a") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948f044cf1f7a64fa4df4b") }Display all documents from a collection with the help of find() method. The query is as follows −> db.updateManyDocumentsDemo.find().pretty();The following is the ... Read More

Declare syntax error in MySQL Workbench?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

3K+ Views

The DECLARE syntax must between BEGIN and END. The syntax is as follows −BEGIN DECLARE yourVariableName1 dataType, DECLARE yourVariableName2 dataType, . . . . ENDHere is the query to avoid DECLARE syntax error in MySQL −mysql> DELIMITER // mysql> create procedure declare_Demo()    -> BEGIN    -> DECLARE Name varchar(100);    -> SET Name: ='John';    -> SELECT Name;    -> END    -> // Query OK, 0 rows affected (0.17 sec) mysql> DELIMITER ;Call the stored procedure with the help of CALL command. The syntax is as follows −CALL yourStoredProcedureName();The query is as follows −mysql> call declare_Demo();The following is ... Read More

Is it possible to cast in a MongoDB Query?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

327 Views

Yes, it is possible to cast in a MongoDB query −db.yourCollectionName.find("this.yourFieldName >yourValue);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.castingDemo.insertOne({"Amount":"200"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e874cf1f7a64fa4df42") } > db.castingDemo.insertOne({"Amount":"100"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e8e4cf1f7a64fa4df43") } > db.castingDemo.insertOne({"Amount":"110"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e944cf1f7a64fa4df44") } > db.castingDemo.insertOne({"Amount":"95"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e9d4cf1f7a64fa4df45") } > db.castingDemo.insertOne({"Amount":"85"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947ea44cf1f7a64fa4df46") } > db.castingDemo.insertOne({"Amount":"75"}); {    "acknowledged" ... Read More

Match between fields in MongoDB aggregation framework?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

269 Views

      You can use $cmp 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.matchBetweenFieldsDemo.insertOne({"FirstValue":40, "SecondValue":70}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c9625259fcd19549980d") } > db.matchBetweenFieldsDemo.insertOne({"FirstValue":20, "SecondValue":5}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c96b5259fcd19549980e") }Display all documents from a collection with the help of find() method. The query is as follows −> db.matchBetweenFieldsDemo.find().pretty();The following is the output −{    "_id" : ObjectId("5c92c9625259fcd19549980d"),    "FirstValue" : 40,    "SecondValue" : 70 } {    "_id" : ... Read More

Check replication type in MySQL?

Samual Sam
Updated on 30-Jul-2019 22:30:25

444 Views

To check replication type, you can use SHOW GLOBAL VARIABLES command. The syntax is as follows −SHOW GLOBAL VARIABLES LIKE 'binlog_format';The above syntax returns either ROW, MIXED or STATEMENT. The default resultant is ROW.Now you can implement the above syntax to check replication type. The query is as follows −mysql> SHOW GLOBAL VARIABLES LIKE 'binlog_format';Here is the output −+---------------+-------+ | Variable_name | Value | +---------------+-------+ | binlog_format | ROW | +---------------+-------+ 1 row in set (0.10 sec)Here is the query to switch from ROW to STATEMENT −mysql> SET GLOBAL binlog_format = 'STATEMENT'; Query OK, 0 rows affected (0.04 ... Read More

How to get the equivalent for SELECT column1, column2 FROM tbl in MongoDB Database?

Anvi Jain
Updated on 30-Jul-2019 22:30:25

251 Views

The equivalent syntax is as follows.db.yourCollectionName.find({}, {_id: 1, "column1": 1, "column2": 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.equivalentForSelectColumn1Column2Demo.insertOne({"CustomerName":"John", "CustomerAge":26, "CustomerCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c6205259fcd19549980a") } > db.equivalentForSelectColumn1Column2Demo.insertOne({"CustomerName":"David", "CustomerAge":22, "CustomerCountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c6305259fcd19549980b") } > db.equivalentForSelectColumn1Column2Demo.insertOne({"CustomerName":"Chris", "CustomerAge":24, "CustomerCountryName":"UK"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c6415259fcd19549980c") }Display all documents from a collection with the help of find() method. The query is as follows −> db.equivalentForSelectColumn1Column2Demo.find().pretty();The following is the output ... Read More

MySQL select accumulated (running sum) column?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

270 Views

To select accumulated column, let us first create a demo table. The query to create a table is as follows −mysql> create table accumulatedDemo    -> (    -> Value int    -> ); 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 accumulatedDemo values(10); Query OK, 1 row affected (0.21 sec) mysql> insert into accumulatedDemo values(15); Query OK, 1 row affected (0.09 sec) mysql> insert into accumulatedDemo values(20); Query OK, 1 row affected (0.13 sec) mysql> insert into accumulatedDemo values(25); Query OK, 1 row affected ... Read More

MongoDB query by sub-field?

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

You can use dot(.) notation to query by subfield. Let us create a collection with a document. The query to create a collection with a document is as follows −> db.queryBySubFieldDemo.insertOne(    ... {       ... "StudentPersonalDetails" : {"StudentName" : "John", "StudentHobby" :"Photography"},       ... "StudentScores" : {"MathScore" : 56}    ... } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c2995259fcd195499808") } > db.queryBySubFieldDemo.insertOne(    ... {       ... "StudentPersonalDetails" : {"StudentName" : "Chris", "StudentHobby" :"Reading"},       ... "StudentScores" : {"MathScore" : 97}    ... } ... ); { ... Read More

Advertisements