George John has Published 1081 Articles

What are the difference ways to replace nulls values in MySQL using SELECT statement?

George John

George John

Updated on 30-Jun-2020 07:57:57

1K+ Views

There are lots of options available to replace NULL values using select statement. You can use CASE statement or IFNULL() or COALESCE()Case 1 − Using IFNULL()The syntax of IFNULL() is as follows −SELECT IFNULL(yourColumnName, ’yourValue’) AS anyVariableName from yourTableName;Case 2 − Using COALESCE()The syntax of COALESCE() is as follows −SELECT ... Read More

How can I change root username in MySQL?

George John

George John

Updated on 30-Jun-2020 07:45:45

3K+ Views

To change the root username in MySQL, you need to use UPDATE and SET command. The syntax is as follows −UPDATE user set user = ’yourNewUserName’ WHERE user = ’root’;To understand the above syntax, let us switch the database to MySQL using USE command.The query is as follows to switch ... Read More

Replace 0 with null in MySQL?

George John

George John

Updated on 30-Jun-2020 07:36:05

2K+ Views

You can use NULLIF() from MySQL to replace 0 with NULL. The syntax is as follows −SELECT *, NULLIF(yourColumnName, 0) as anyVariableName from yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table Replace0WithNULLDemo    -> (   ... Read More

MySQL LIMIT to select a single row

George John

George John

Updated on 30-Jun-2020 07:28:32

485 Views

To select a single row in MySQL, you can use LIMIT. At first, let us create a table. The query to create a table is as follows −mysql> create table selectWithPrimaryKey    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,   ... Read More

MySQL order by string with numbers?

George John

George John

Updated on 30-Jun-2020 07:20:00

6K+ Views

To MySQL order string with numbers, the following is the syntax, wherein we have used ORDER BY, SUBSTR() and CAST() −SELECT *FROM yourTableName ORDER BY SUBSTR(yourColumnName FROM 1 FOR 2), CAST(SUBSTR(yourColumnName FROM 2) AS UNSIGNED);To understand the above syntax, let us create a table. The query to create a table ... Read More

MySQL select * with distinct id?

George John

George John

Updated on 30-Jun-2020 07:06:04

2K+ Views

You can use GROUP BY command for select with distinct id. The syntax is as follows −SELECT *FROM yourTableName GROUP BY yourColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DistinctIdDemo    -> (    -> Id ... Read More

Select distinct combinations from two columns in MySQL?

George John

George John

Updated on 30-Jun-2020 06:53:01

4K+ Views

To select distinct combinations from two columns, you can use CASE statement. Let us create a table with some columns.The query to create a table is as follows −mysql> create table select_DistinctTwoColumns    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> FirstValue char(1),    -> SecondValue char(1), ... Read More

Order by last 3 chars in MySQL?

George John

George John

Updated on 30-Jun-2020 06:48:25

19K+ Views

You can use ORDER BY RIGHT() function to order by last 3 chars in MySQL. The syntax is as follows −SELECT *FROM yourTableName ORDER BY RIGHT(yourColumnName, 3) yourSortingOrder;Just replace the ‘yourSortingOrder’ to ASC or DESC to set the ascending or descending order respectively.To understand the above syntax, let us create ... Read More

What are intent-filters in Android?

George John

George John

Updated on 30-Jun-2020 05:29:17

5K+ Views

An intent filter is an instance of the IntentFilter class. Intent filters are helpful while using implicit intents, It is not going to handle in java code, we have to set it up in AndroidManifest.xml. Android must know what kind of intent it is launching so intent filters give the ... Read More

Loop through an ArrayList using an Iterator in Java

George John

George John

Updated on 29-Jun-2020 13:56:42

4K+ Views

An Iterator can be used to loop through an ArrayList. The method hasNext( ) returns true if there are more elements in ArrayList and false otherwise. The method next( ) returns the next element in the ArrayList and throws the exception NoSuchElementException if there is no next element.A program that ... Read More

Previous 1 ... 5 6 7 8 9 ... 109 Next
Advertisements