Skip to content

Commit b96b8d7

Browse files
committed
understanding ifNULL function in sql statement
1 parent 81e9cbd commit b96b8d7

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ifNULL function.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use temp_db;
2+
3+
show tables;
4+
5+
create table emp_3(id int, salary int);
6+
7+
insert into emp_3 values(1, 10000);
8+
insert into emp_3 values(2, 14253);
9+
insert into emp_3 values(NULL, 1000);
10+
insert into emp_3 values(4, NULL);
11+
12+
select * from emp_3;
13+
14+
-- if we add the value in the NULL
15+
16+
select (salary + 20000) from emp_3; -- here null + 20000 is NULL
17+
18+
select (ifNULL(salary, 0) + 10) from emp_3; -- now it will show 10 where ever is NULL value

0 commit comments

Comments
 (0)