Anvi Jain has Published 629 Articles

Query array of nested string with MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

126 Views

To query array of nested string, you can use the dot(.) notation. Let us first create a collection with documents −> db.nestedStringDemo.insertOne(    {       "CustomerName": "John",       "CustomerOtherDetails": [ { "Age":29, "CountryName": "US" },       { "CompanyName": "Amazon",       "Salary": 150000, ... Read More

Select and add result of multiplying two columns from a table in MySQL?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

581 Views

You can use aggregate function SUM() for this. Let us first create a table −mysql> create table DemoTable    (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerProductName varchar(100),    CustomerProductQuantity int,    CustomerPrice int    ); Query OK, 0 rows affected (0.17 sec)Insert some records in the ... Read More

Java DatabaseMetaData getMaxColumnNameLength() method with example.

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

99 Views

The getMaxColumnNameLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters that the underlying database allows in the name of a column.This method returns an integer value, representing the maximum number of characters allowed in a column name. If this value is 0 it ... Read More

How to query soundex() in MySQL?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

164 Views

The SOUNDEX() returns a soundex string. Two strings that sound almost the same should have identical soundex stringsTo query soundex() in MySQL, you can use the below syntax −select *from yourTableName where soundex(yourValue)=soundex(yourColumnName);Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT ... Read More

Get distinct first word from a string with MongoDB?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

133 Views

To get distinct first word from a string, you can use distinct(). Let us first create a collection with documents −> db.distinctFirstWordDemo.insertOne(    {       "_id": 100,       "StudentName":"John",       "StudentFeature": "John is a good player",       "Subject":"MongoDB"    } ); { ... Read More

Java DatabaseMetaData getMaxUserNameLength() method with example.

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

18 Views

The getMaxUserNameLength() method of the DatabaseMetaData interface is used to find out the maximum number of characters that the underlying database allows in the name of a user.This method returns an integer value, representing the maximum number of characters allowed in a user name. If this value is 0 it indicates ... Read More

Ordering string as a number in a database?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

72 Views

To order string as a number, use CAST(). Following is the syntax −select *from yourTableName ORDER BY CAST(yourColumnName AS SIGNED) DESC;Let us first create a table −mysql> create table DemoTable    (    Id varchar(100)    ); Query OK, 0 rows affected (0.18 sec)Insert some records in the table using ... Read More

How to sum based on field value in MySQL?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

300 Views

To sum based on field values, use aggregate function SUM() along with CASE statement. Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Price int,    isValidCustomer boolean,    FinalPrice int    ); Query OK, 0 rows affected ... Read More

Java DatabaseMetaData getMaxColumnsInSelect() method with example.

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

18 Views

The getMaxColumnsInSelect() method of the DatabaseMetaData interface is used to find out the maximum number of columns that the underlying database allows in a SELECT list.This method returns an integer value, representing the maximum number of columns allowed in a SELECT list. If this value is 0 it indicates that ... Read More

How to select only MySQL date from datetime column?

Anvi Jain

Anvi Jain

Updated on 30-Jul-2019 22:30:26

393 Views

Use DATE_FORMAT for this. Let us first create a table −mysql> create table DemoTable    (    ShippingDate varchar(200)     ); Query OK, 0 rows affected (0.25 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('04:58 PM 10/31/2018'); Query OK, 1 row affected (0.10 ... Read More

Advertisements