George John has Published 1081 Articles

Sort by character length in MySQL

George John

George John

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

5K+ Views

To sort by character length in MySQL use the ORDER BY LENGTH(). Let us first create a table:mysql> create table orderingAADemo    -> (    -> Value varchar(100)    -> ); Query OK, 0 rows affected (1.30 sec)Following is the query to insert some records in the table using insert ... Read More

How to convert bool to int in MySQL?

George John

George John

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

1K+ Views

To convert bool to int in MySQL, you can use CAST(). Let us first create a table:mysql> create table convertBoolToIntDemo -> ( -> isYoung bool -> ); Query OK, 0 rows affected (0.69 sec)Following is the query to insert some records ... Read More

Total number of fields in all tables in database?

George John

George John

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

765 Views

To get total number of fields in all tables in database, you can use information_schema.columns along with aggregate function count(*).We are using ‘sample’ database which consists of a lot of tables with fields. Following is the query to get total number of fields in all tables in database:mysql> SELECT COUNT(*) ... Read More

IntStream of() method in Java

George John

George John

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

476 Views

The IntStream class in Java the following two forms of of() methodIntStream of(int t) methodThe following of() method returns a sequential IntStream containing a single element. Here is the syntaxstatic IntStream of(int t)Here, parameter t is the single element.IntStream of(int… values) methodThe following of() method returns a sequentially ordered stream ... Read More

Collectors maxBy() method in Java 8

George John

George John

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

2K+ Views

The maxBy() method of the Collectors class in Java 8 returns a Collector that produces the maximal element according to a given Comparator, described as an Optional.The syntax is as followsstatic Collector maxBy(Comparator

How to change a primary key in MySQL to auto_increment?

George John

George John

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

4K+ Views

To change a primary key to auto_increment, you can use MODIFY command. Let us first create a table.mysql> create table changePrimaryKeyInAutoIncrement    -> (    -> StudentId int not null primary key,    -> StudentName varchar(100),    -> StudentAge int,    -> StudentAddress varchar(100)    -> ); Query OK, 0 ... Read More

Increment a value in a MongoDB nested object?

George John

George John

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

490 Views

To increment a value in nested object, you can use $inc operator. Let us first implement the following query to create a collection with documents>db.incrementValueDemo.insertOne({"StudentName":"Larry", "StudentCountryName":"US", "StudentDetails":[{"StudentSubjectName":"Math", "StudentMathMarks":79}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986ca0330fd0aa0d2fe4a2") }Following is the query to display all documents from a collection with the ... Read More

Count value for multiple columns in MySQL?

George John

George John

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

600 Views

To count value for multiple columns, use the CASE statement. Let us first create a table::mysql> create table countValueMultipleColumnsDemo    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.62 sec)Following is the query to insert some ... Read More

In a MySQL schema, what is the meaning of “AUTO_INCREMENT=3”

George John

George John

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

303 Views

In MySQL, AUTO_INCREMENT=3 tells that the inserted record will start from 3 not the default 1. Let us first create a sample table and set auto increment to 3:mysql> create table Auto_incrementDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ... Read More

Can MySQL concatenate strings with ||?

George John

George John

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

166 Views

Yes, you can concatenate strings with || in MySQL with the help of sql_mode. Set the sql_mode to PIPES_AS_CONCAT.The syntax is as followsset sql_mode=PIPES_AS_CONCAT;The following is the syntax to concat with the help of ||.SELECT ‘yourValue' || yourColumName AS anyAliasName FROM yourTableName;To understand the above syntax, let us create a ... Read More

Advertisements