AmitDiwan has Published 11365 Articles

Replace only a specific value from a column in MySQL

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 06:47:28

8K+ Views

To replace, use the REPLACE() MySQL function. Since you need to update the table for this, use the UPDATE() function with the SET clause.Following is the syntax −update yourTableName set yourColumnName=replace(yourColumnName, yourOldValue, yourNewValue);Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    CountryName varchar(100) ); ... Read More

MySQL query to place a specific record on the top

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 06:44:35

129 Views

For this, you can use the ORDER BY CASE statement. Let us first create a table −mysql> create table DemoTable (    StudentName varchar(100),    StudentMarks int ); Query OK, 0 rows affected (0.97 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 45); Query ... Read More

MySQL query to order by the first number in a set of numbers?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 06:41:39

150 Views

To order by the first number in a set of numbers, use ORDER BY SUBSTRING_INDEX(). Let us first create a table −mysql> create table DemoTable (    SetOfNumbers text ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('245, ... Read More

Can we use reserved word ‘index’ as MySQL column name?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 06:39:27

521 Views

Yes, but you need to add a backtick symbol to the reserved word (index) to avoid error while using it as a column name.Let us first create a table −mysql> create table DemoTable (    `index` int ); Query OK, 0 rows affected (0.48 sec)Insert some records in the table ... Read More

Getting maximum from a column value and set it for all other values in the same column with MySQL?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 06:31:40

58 Views

Let us first create a table −mysql> create table DemoTable (    FirstName varchar(100),    Score int ); Query OK, 0 rows affected (0.60 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('David', 59); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable ... Read More

Compare for NULL value and display value 1 for these values in a new MySQL column?

AmitDiwan

AmitDiwan

Updated on 27-Sep-2019 06:29:11

60 Views

For this, use IF() along with IS NULL property. Let us first create a table −mysql> create table DemoTable (    Name varchar(100),    CountryName varchar(100) ); Query OK, 0 rows affected (0.70 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('Chris', 'US'); Query OK, ... Read More

EnumMap class in Java

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 13:27:04

133 Views

The java.util.EnumMap class is a specialized Map implementation for use with enum keys. Following are the important points about EnumMap −All of the keys in an enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is created.Enum maps are maintained in the natural ... Read More

Compare two Strings in Java

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 13:23:44

288 Views

Compare two strings using compareTo() method in Java. The syntax is as follows −int compareTo(Object o)Here, o is the object to be compared.The return value is 0 if the argument is a string lexicographically equal to this string; a value less than 0 if the argument is a string lexicographically ... Read More

Java streams counting() method with examples

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 13:13:13

244 Views

Count the number of elements in the stream using the Java streams counting() method. Following is an example to implement the Java Streams counting() method −Example Live Demoimport java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo {    public static void main(String[] args) {       Stream stream = Stream.of("Kevin", ... Read More

Java Stream findAny() with examples

AmitDiwan

AmitDiwan

Updated on 26-Sep-2019 13:10:57

757 Views

The findAny() method of the Java Stream returns an Optional for some element of the stream or an empty Optional if the stream is empty. Here, Optional is a container object which may or may not contain a non-null value.Following is an example to implement the findAny() method in Java ... Read More

Advertisements