Nishtha Thakur

Nishtha Thakur

398 Articles Published

Articles by Nishtha Thakur

Page 27 of 40

Count number of elements in an array with MongoDB?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 1K+ Views

To count number of elements in an array, use the aggregate framework. Let us first create a collection with documents −>db.countNumberOfElementsDemo.insertOne({"UserMessage":["Hi", "Hello", "Bye", "Awesome"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cef8ec2ef71edecf6a1f6a1") }Display all documents from a collection with the help of find() method −> db.countNumberOfElementsDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cef8ec2ef71edecf6a1f6a1"),    "UserMessage" : [       "Hi",       "Hello",       "Bye",       "Awesome"    ] }Following is the query to count number of elements in an array −> db.countNumberOfElementsDemo.aggregate({$project: { NumberOfElements: { $size:"$UserMessage" }}})This will produce ...

Read More

Apostrophe replacement in MySQL query?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 646 Views

To replace apostrophe, you can use replace(). Following is the syntax −update yourTableName set yourColumnName=replace(yourColumnName, '\'', '');Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Sentence varchar(100)    ); Query OK, 0 rows affected (0.17 sec)Insert some records in the table using insert command. Apostrophe is added for the sentence −mysql> insert into DemoTable(Sentence) values('Chris\'s Father'); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable(Sentence) values('Larry\'s Mother'); Query OK, 1 row affected (0.06 sec)Display all records from the table using select statement −mysql> select *from ...

Read More

Java DatabaseMetaData getMaxColumnsInOrderBy() method with example.

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 105 Views

The getMaxColumnsInOrderBy() method of the DatabaseMetaData interface is used to find out the maximum number of columns that the underlying database allows in an ORDER BY clause.This method returns an integer value, representing the maximum number of columns allowed in an ORDER BY clause. If this value is 0 it indicates that there is no limit or, limit is unknown.To get the DatabaseMetaData object −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() ...

Read More

Pull row with lowest number in a MySQL column?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 132 Views

Use aggregate function MIN() along with GROUP BY for this. Here, we will display the minimum ID for NumberOfProduct . Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    NumberOfProduct int    ); Query OK, 0 rows affected (0.19 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(NumberOfProduct) values(40); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable(NumberOfProduct) values(40); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable(NumberOfProduct) values(60); Query OK, 1 row affected (0.07 sec) mysql> ...

Read More

Java DatabaseMetaData getMaxConnections() method with example.

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 377 Views

The getMaxConnections() method of the DatabaseMetaData interface is used to find out the maximum number of connections that the underlying database allows at a time.This method returns an integer value, representing the maximum number of connections allowed at a time. If this value is 0 it indicates that there is no limit or, limit is unknown.To get the DatabaseMetaData object −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method of the DriverManager class. ...

Read More

MySQL Stored Procedure to create a table?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 3K+ Views

Following is the query to create a stored procedure that creates a table. Here, we are creating a table with three columns, one of them is Id −mysql> DELIMITER //    mysql> CREATE PROCEDURE Stored_Procedure_CreatingTable()    BEGIN       create table DemoTable       (       Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,       UserFirstName varchar(20),       UserLastName varchar(20)       );    END;    //    Query OK, 0 rows affected (0.16 sec) mysql> DELIMITER ;Now you can call stored procedure with the help of CALL command −mysql> call Stored_Procedure_CreatingTable(); ...

Read More

Java DatabaseMetaData getMaxStatementLength() method with example.

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 144 Views

The getMaxStatementLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters that the underlying database allows in a single SQL statement.This method returns an integer value, representing the maximum number of characters allowed in an SQL statement. If this value is 0 it indicates that there is no limit or, limit is unknown.To get the DatabaseMetaData object −Make sure your database is up and running.Register the driver using the registerDriver() method of the DriverManager class. Pass an object of the driver class corresponding to the underlying database.Get the connection object using the getConnection() method ...

Read More

MySQL Select when a grouped record has multiple matching strings?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 129 Views

You can use regular expression for this. Let us first create a table −mysql> create table DemoTable    (    ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    ProductName varchar(20)    ); Query OK, 0 rows affected (0.19 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(ProductName) values('Product-1'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(ProductName) values('Product2'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(ProductName) values('Product1'); Query OK, 1 row affected (0.04 sec) mysql> insert into DemoTable(ProductName) values('Product-3'); Query OK, 1 row affected (0.05 sec) mysql> ...

Read More

Fetch data between two rows in MySQL?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 479 Views

To fetch data between two rows, use the concept of LIMIT. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Name varchar(10)    ); Query OK, 0 rows affected (0.22 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Name) values('Larry'); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable(Name) values('Robert'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('Chris'); Query OK, 1 row affected (0.05 sec) mysql> insert into DemoTable(Name) values('David'); Query OK, 1 row affected ...

Read More

How can we sort a query using ORDER BY CASE WHEN REGEXP?

Nishtha Thakur
Nishtha Thakur
Updated on 30-Jul-2019 645 Views

Use regular expression along with CASE statement. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Value varchar(20)    ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Value) values('101'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable(Value) values('P'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable(Value) values('A'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(Value) values('53'); Query OK, 1 row affected (0.13 sec) mysql> ...

Read More
Showing 261–270 of 398 articles
« Prev 1 25 26 27 28 29 40 Next »
Advertisements