What is SELECT in SQL SERVER PART 10 With Example Code

These SQL SELECT statements cover various scenarios for querying data from tables in a database.Let me know if you need further clarification or assistance with any specific part!

 


 
SELECT DISTINCT FirstName, LastName FROM Customers;
 
SELECT Name, Email FROM Employee WHERE Department = 'IT';
 
SELECT * FROM Products;
 
SELECT City, Country FROM Customers;
 
SELECT COUNT(*) AS TotalRows FROM YourTableName;
 
SELECT SUM(Salary) AS TotalSalary FROM EmployeeTable;
 
SELECT AVG(Age) AS AverageAge FROM PersonTable;
 
SELECT MIN(Price) AS LowestPrice FROM ProductTable;
 
SELECT MAX(Score) AS HighestScore FROM ExamResults;
 
SELECT Department, AVG(Salary) AS AverageSalary FROM Employee GROUP BY Department;
 
SELECT Country, City, COUNT(*) AS CustomerCount FROM Customers GROUP BY Country, City;
 
SELECT Category, AVG(Price) AS AveragePrice FROM Products GROUP BY Category HAVING AVG(Price) > 50;
 
SELECT Department, SUM(Salary) AS TotalSalary FROM Employee GROUP BY Department ORDER BY TotalSalary DESC;
 
SELECT * FROM Customers WHERE ContactName LIKE '%Hi%';
 
SELECT Department, AVG(Salary) AS AverageSalary FROM Employee
WHERE Salary > 40000
GROUP BY Department
HAVING AVG(Salary) > 50000;
 
SELECT ProductCategory, SUM(SalesAmount) AS TotalSales
FROM Sales
WHERE SalesDate > '2023-01-01'
GROUP BY ProductCategory
HAVING SUM(SalesAmount) > 1000
ORDER BY TotalSales DESC;
 
SELECT Country, City, COUNT(*) AS CustomerCount
FROM Customers
WHERE Country = 'USA'
GROUP BY Country, City;
 
-- Select records from Table1 where ID is not in Table2
SELECT * FROM Table1
WHERE ID NOT IN (SELECT ID FROM Table2);
 
-- Select employees from HR or IT departments
SELECT * FROM Employees
WHERE Department IN ('HR', 'IT');
 
-- Select products whose name contains 'berry'
SELECT * FROM Products
WHERE ProductName LIKE '%Hi%';