George John has Published 1167 Articles

Can we order a MySQL result with mathematical operations?

George John

George John

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

200 Views

Yes, we can order with mathematical operations using ORDER BY clause. Let us first create a table:mysql> create table orderByMathCalculation    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Quantity int,    -> Price int    -> ); Query OK, 0 rows affected (0.57 sec)Following ... Read More

How to add column using alter in MySQL?

George John

George John

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

141 Views

Following is the syntax to add column using alter in MySQL:alter table yourTableName add column yourColumnName yourDataType default yourValue;Let us first create a table:mysql> create table alterTableDemo    -> (    -> Id int,    -> Name varchar(10)    -> ); Query OK, 0 rows affected (0.69 sec)Let us check ... Read More

How to suppress MySQL stored procedure output?

George John

George John

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

839 Views

To suppress MySQL stored procedure output, you can use variable. Let us first create a table.mysql> create table person_information    -> (    -> Id int,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.50 sec)Following is the query to insert some records in the table ... Read More

Write a MySQL query equivalent to “SHOW TABLES” in sorted order?

George John

George John

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

81 Views

Use INFORMATION_SCHEMA.TABLES to display tables in sorted order. The below syntax will give sorted list of tables in ascending order:select TABLE_NAME from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA= 'yourDatabaseName' order by TABLE_NAME;Following is the query to implement the equivalent to SHOW TABLES:mysql> select TABLE_NAME from INFORMATION_SCHEMA.TABLES    -> where TABLE_SCHEMA= 'sample' order by ... Read More

The codePoints() method in Java IntStream

George John

George John

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

331 Views

The codePoint() method is used to display a stream of code point values from the given sequence.The syntax is as followsIntStream codePoints()To work with Java IntStream class, you need to import the following packageimport java.util.stream.IntStream;Here is our stringString myStr = "Example!";Now, get the code point valuesIntStream intStream = myStr.codePoints();The following ... Read More

MySQL query to get the count of rows in which two or more specified values appear?

George John

George John

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

57 Views

To get the count of rows in which two or more specified values appear, let us first create a sample table:mysql> create table specifiedValuesDemo -> ( -> Value int, -> Value2 int, -> Value3 int ... Read More

How to create double nested array in MongoDB?

George John

George John

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

274 Views

To create a double nested array in MongoDB, let us implement the query to create a collection with documents. Within that, we have created a double nested array that displays Student Details, with the project name and technologies used to develop the same project:> db.doubleNestedArrayDemo.insertOne( ... { ...    "StudentId" ... Read More

Sort by character length in MySQL

George John

George John

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

3K+ 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

538 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

Advertisements