If you use COUNT(*) around the LEAST() then MySQL scans at least one index, therefore avoid LEAST(COUNT(*)) and use LIMIT.Let us first create a table. The query to create a table is as follows −mysql> create table ReturnDemo -> ( -> Id int, -> Name varchar(10) -> ); Query OK, 0 rows affected (0.79 sec)ExampleNow you can insert some records in the table using insert command. The query is as follows −mysql> insert into ReturnDemo values(100, 'Larry'); Query OK, 1 row affected (0.18 sec) mysql> insert into ReturnDemo values(101, 'Bob'); Query OK, 1 row affected (0.28 sec) mysql> insert into ... Read More
To convert int to boolean, let us first take the following int.int one = 1; int two = 1; int three = 0;We have nested if-else statement to display the true or false values. Here, the value “one” is the same as “two” i.e. 1; therefore, the following works −else if (one.equals(two)) { System.out.println(true); }The above display “true” and in this way we converted int to boolean.Let us now see the complete example to learn how to convert int to Boolean.Example Live Demopublic class Demo { public static void main(String[] args) { int one = 1; ... Read More
To perform XOR on a set of Booleans, firstly let us consider the following Boolean array.boolean[] arr = { true, true, false };Let us now create a nested loop and within that perform XOR operation.for (boolean one : arr) { for (boolean two: arr) { // XOR boolean res = one ^ two; } }Here is the entire example to displayXOR on a set of Booleans.Example Live Demopublic class Demo { public static void main(String[] args) { // boolean array boolean[] arr = { true, true, ... Read More
To understand the GROUP BY and MAX on multiple columns, let us first create a table. The query to create a table is as follows −mysql> create table GroupByMaxDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CategoryId int, -> Value1 int, -> Value2 int -> ); Query OK, 0 rows affected (0.68 sec)ExampleInsert some records in the table using insert command. The query is as follows −mysql> insert into GroupByMaxDemo(CategoryId, Value1, Value2) values(10, 100, 50); Query OK, 1 row affected (0.15 sec) mysql> insert into GroupByMaxDemo(CategoryId, Value1, Value2) values(10, 100, ... Read More
To check for Integer overflow, we need to check the Integer.MAX_VALUE, which is the maximum value of an integer in Java.Let us see an example wherein integers are added and if the sum is more than the Integer.MAX_VALUE, then an exception is thrown.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 9898989; int val2 = 6789054; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); long sum = (long)val1 + (long)val2; if (sum > Integer.MAX_VALUE) { throw ... Read More
To get the minimum value of datatype int in Java, use the following −Integer.MIN_VALUETo get the maximum value of datatype int in Java, use the following −Integer.MAX_VALUELet us now implement this in our example.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 20; int val2 = 3000; System.out.println("Value1: "+val1); System.out.println("Value2: "+val2); System.out.println("Maximum value: "+Integer.MIN_VALUE); System.out.println("Minimum value: "+Integer.MAX_VALUE); } }OutputValue1: 20 Value2: 3000 Maximum value: -2147483648 Minimum value: 2147483647
Let us first create a table −mysql> create table OrderDemo -> ( -> OrderId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> OrderPrice int, -> OrderDatetime datetime -> ); Query OK, 0 rows affected (0.66 sec)ExampleNow you can insert some records in the table using insert command. The query is as follows −mysql> insert into OrderDemo(OrderPrice, OrderDatetime) values(200, '2016-09-12'); Query OK, 1 row affected (0.24 sec) mysql> insert into OrderDemo(OrderPrice, OrderDatetime) values(NULL, '2002-11-18'); Query OK, 1 row affected (0.26 sec) mysql> insert into OrderDemo(OrderPrice, OrderDatetime) values(1000, '2017-12-28'); Query OK, 1 row affected (0.15 sec)Display all records ... Read More
The following is an example displaying the maximum of three integer values.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 10; int val2 = 20; int val3 = 30; System.out.println("Number 1 = "+val1); System.out.println("Number 2 = "+val2); System.out.println("Number 3 = "+val3); if (val2 > val1) { val1 = val2; } if (val3 > val1) { val1 = val3; ... Read More
The following is an example displaying the minimum of three integer values.Example Live Demopublic class Demo { public static void main(String[] args) { int val1 = 99; int val2 = 87; int val3 = 130; System.out.println("Number 1 = "+val1); System.out.println("Number 2 = "+val2); System.out.println("Number 3 = "+val3); if (val2 < val1) { val1 = val2; } if (val3 < val1) { val1 = val3; ... Read More
Primitive datatypes are predefined by the language and named by a keyword in Java. Here is an example to display the default value of primitive data types.Example Live Demopublic class Demo { static boolean val1; static double val2; static float val3; static int val4; static long val5; static String val6; public static void main(String[] args) { System.out.println("Default values....."); System.out.println("Val1 = " + val1); System.out.println("Val2 = " + val2); System.out.println("Val3 = " + val3); System.out.println("Val4 = " + val4); ... Read More