Tuesday, December 20, 2022

Difference between count(*) and count(column_name)

 ---DAY 4
--#15DAYSSQLCHALLENGE
--Difference between count(*) and count(column_name) in SQL

--Count(*) will count the null value
--count(column_name) will not count the null value 


------------------------------START -------------------

SELECT REPLICATE('*',200) AS 'SOLUTION'


 SELECT * FROM [dbo].[emp_2020] 

 SELECT * FROM  [dbo].[emp_2021]


SELECT REPLICATE('*',200) AS 'JOIN THE ABOVE TWO TABLE WITH FULL OUTER JOIN '


 SELECT *   FROM [dbo].[emp_2020] E_20 FULL   JOIN 
 [dbo].[emp_2021] E_21
 ON E_20.emp_id=E_21.emp_id


 SELECT  COUNT (* ) 'Count the no of records in the table' ,REPLICATE('*',200) AS 'COUNT (*) --count the null value '   FROM [dbo].[emp_2020] E_20 FULL   JOIN 
 [dbo].[emp_2021] E_21
 ON E_20.emp_id=E_21.emp_id


  SELECT  COUNT (e_21.designation) 'Count of designation'   ,REPLICATE('*',200) AS ' COUNT (COLUMN NAME)--Here it will not count the null  ' 

 FROM [dbo].[emp_2020] E_20 FULL   JOIN 
 [dbo].[emp_2021] E_21
 ON E_20.emp_id=E_21.emp_id


 SELECT REPLICATE('*',200) AS 'END OF SOLUTION'


No comments:

Post a Comment

"🚀 Delta Lake's Vectorized Delete: The Secret to 10x Faster Data Operations!"

"🚀 Delta Lake's Vectorized Delete: The Secret to 10x Faster Data Operations!" Big news for data engineers! Delta Lake 2.0+ in...