Today, I am going to share about Where clause usages in SQL Query using Microsoft SQL server and AdventureWorks Database.
We Will gonna use "Production.Product" Table in this examples,
In this blogpost will see about where clause with other operators such as and, or, like, not null, null
Initially we will explore about Simple SQL where clause queries here,
Later I will update more complex SQL where clause queries in future days.
At First we will see the normal Query with resultsets
select * from Production.Product
In this below Query we will see about Safety Stock level value below 1000
select Production.Product.ProductID,
Production.Product.Name,
Production.Product.SafetyStockLevel
from Production.Product
where Production.Product.SafetyStockLevel < 1000
In this below query will explore safety stock level values are above 600\
-- where query for SafetyStock level above 600
select Production.Product.ProductID,
Production.Product.Name,
Production.Product.SafetyStockLevel
from Production.Product
where Production.Product.SafetyStockLevel > 600
select Production.Product.ProductID,Production.Product.Name,Production.Product.SafetyStockLevelfrom Production.Productwhere Production.Product.SafetyStockLevel < 500 orProduction.Product.SafetyStockLevel > 800
select Production.Product.ProductID,Production.Product.Name,Production.Product.SafetyStockLevelfrom Production.Productwhere Production.Product.SafetyStockLevel > 100 andProduction.Product.SafetyStockLevel < 800
select Production.Product.ProductID,Production.Product.Name,Production.Product.ProductNumber,Production.Product.SafetyStockLevelfrom Production.Productwhere Production.Product.ProductNumber like 'C%'
select Production.Product.ProductID,Production.Product.Name,Production.Product.ProductNumber,Production.Product.SafetyStockLevelfrom Production.Productwhere Production.Product.ProductNumber like '%7'
select Production.Product.ProductID,
Production.Product.Name,
Production.Product.ProductNumber,
Production.Product.SafetyStockLevel
from Production.Product
where Production.Product.ProductNumber like '%8%'
select * from Production.Product where Color is not null
select * from Production.Product where Color is null
select * from Production.Product where ReorderPoint between 10 and 600
-- where between and like operator
select * from Production.Product where ProductNumber like 'C%' and ReorderPoint between 10 and 600
Comments
Post a Comment
Share this to your friends