If we want to get first not null value we have function in mysql to get this result

COALESCE

Example :

TABLE STRUCTURE
——————————————–
| id | customername | mobile | home | work |
——————————————–
| 1 | Joe | 123 | 456 | 789 |
——————————————–
| 2 | Jane | | 654 | 987 |
——————————————–
| 3 | John | | | 321 |
——————————————–

SELECT id, customername, COALESCE(mobile, home, work) AS phone FROM customers

RESULT
——————————
| id | customername | phone |
——————————
| 1 | Joe | 123 |
——————————
| 2 | Jane | 654 |
——————————
| 3 | John | 321 |
——————————

 

 

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...