2023.08.15-Nullif, Diff BTWN Coalesce&nullif, Joins Basics-Notes
2023.08.15-Nullif, Diff BTWN Coalesce&nullif, Joins Basics-Notes
Hot it will work: whatever first column is having not null value that column data
will display in output
*****************************************************************************
Nullif():
As per the requirement if you want to convert not null values to null values then
we have to use nullif() function.
syntax:
nulif(col1,value1)
eg: nullif(did,10)
*****************************************************************************
Difference between coalesce() and nullif():
coalesce() --> null to not null
nulif() --> not null to null
q1
union
q2
q2
union
q1
==> Both are same
q1
minus
q2
q2
minus
q1
==> Both are not same
*****************************************************************************
Joins are complex --> Here we need to understand basics of joins, then it will
become very very easy
Select *
From Emp
JOIN DEP
ON emp.did=dep.did
Select e.eid,e.ename,e.did,d.dname
From Employee e
JOIN DEP d
ON e.did=d.did
e.did
d.did ==> it will give differnt kind of output while using outer joins
as per the requirement we need to give join condition with proper column names
***********************************************************************
JOIN 10 table or 20 tables ==> Yes
Select e.eid,e.ename,d.did,d.dname,x.id1,y.id2
From Employee e
JOIN DEP d
ON e.did=d.did
JOIN X x
ON e.id=x.id
JOIN Y y
on e.id=y.id
***********************************************************************
Inner Joins ==> To get all matched records between both the tables
Outer Joins ==> to get matched and unamtched records
Left outer join
right outer join
Full outer join
Cross Join ==> to get combination of all the records
Select e.eid,e.ename,e.did,d.dname
From Employee e
Full outer JOIN DEP d
ON e.did=d.did
***********************************************************************
mysql>