Krantik Chavan has Published 308 Articles

Select first element of a commaseparated list in MySQL?

Krantik Chavan

Krantik Chavan

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

1K+ Views

To select first element of a comma-separated list, you can use SUBSTRING_INDEX(). Let us first create a table:mysql> create table DemoTable (    CSV_Value varchar(200) ); Query OK, 0 rows affected (0.81 sec)Following is the query to insert some records in the table using insert command. We have inserted records ... Read More

Querying internal array size in MongoDB?

Krantik Chavan

Krantik Chavan

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

160 Views

You can use the $size operator for internal array size in MongoDB. The syntax is as follows:db.internalArraySizeDemo.aggregate(    [       {          $group: {             _id:yourObjectIdValue,             anyFieldName: {$first: {$size: "$yourArrayName" }}       ... Read More

How to select particular range of values in a MySQL table?

Krantik Chavan

Krantik Chavan

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

614 Views

In order to select particular range of values in a MySQL table, you can use WHERE clause. Let us first create a table:mysql> create table DemoTable (    CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    CustomerName varchar(200),    CustomerAge int,    isRegularCustomer bool ); Query OK, 0 rows affected ... Read More

Can I get Age using BirthDate column in a MySQL query?

Krantik Chavan

Krantik Chavan

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

160 Views

To get Age using BirthDate column in a MySQL query, you can use datediff(). Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    DateOfBirth date ); Query OK, 0 rows affected (1.46 sec)Following is the query to insert some records ... Read More

MongoDB Regex Search on Integer Value?

Krantik Chavan

Krantik Chavan

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

1K+ Views

To perform Regex search on integer value, you need to use $where operator. The syntax is as follows:db.yourCollectionName.find({ $where: "/^yourIntegerPatternValue.*/.test(this.yourFieldName)" });To understand the above concept, let us create a collection with document. The query to create a collection with document is as follows:> db.regExpOnIntegerDemo.insertOne({"StudentId":2341234}); {    "acknowledged" : true,   ... Read More

Get the names beginning with a particular character using LIKE in MySQL

Krantik Chavan

Krantik Chavan

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

559 Views

To get the names beginning with a particular character, you need to use LIKE. Let us first create a table:mysql> create table DemoTable (    StudentFirstName varchar(20) ); Query OK, 0 rows affected (1.01 sec)Following is the query to insert some records in the table using insert command:mysql> insert into ... Read More

How to convert string to 24-hour datetime format in MySQL?

Krantik Chavan

Krantik Chavan

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

1K+ Views

To convert string to 24 hour datetime format in MySQL, you can use STR_TO_DATE() method. With that use the following format for datetime as the parameter:'%Y-%m-%d %H:%i:%s'Following is the syntaxSELECT STR_TO_DATE(yourColumnName, '%Y-%m-%d %H:%i:%s') FROM yourTableName;Let us first create a table:mysql> create table DemoTable (ArrivalDate varchar(200)); Query OK, 0 rows affected ... Read More

How to auto-increment value of tables to lower value in MySQL?

Krantik Chavan

Krantik Chavan

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

664 Views

If you’re using InnoDB engine, then you cannot set auto_increment value of tables to lower value. You need to change your engine from InnoDB to MyISAM.Note: The engine MyISAM allows you to set lower value. Here, we are using the same.According to the official documents:You cannot reset the counter to ... Read More

Period toTotalMonths() method in Java

Krantik Chavan

Krantik Chavan

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

31 Views

The total number of months for a particular Period can be obtained using the toTotalMonths() method in the Period class in Java. This method requires no parameters and it returns the total number of months in the Period in the form of a long value.A program that demonstrates this is ... Read More

Period of() method in Java

Krantik Chavan

Krantik Chavan

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

66 Views

The Period can be obtained with the given number of days, months and years using the of() method in the Period class in Java. This method requires a 3 parameters i.e. the number of days, the number of months and the number of years. Also, it returns the Period object ... Read More

Advertisements