Basic Syntax
Basic Syntax
Retrieve all the records which starts with a and it can be not like
percentage is a wildcard means anything starts with it can be also ‘%a’
or ‘%a%’
Use operators
Skip rows
Use left join or right join instead
Select * from database. Table name where Column total > 1000
Select * from database. Table name where Column total Between 1000 and 5000
Select top (100) * where (column) is not null
Select top (100) * where (column) is null
SELECT Student Name from Students WHERE NOT Grade IS NULL
SELECT Product Name from Inventory WHERE NOT ProductStatus = 'Discontinued'
SELECT Order ID from Orders WHERE NOT (Order Amount >= 100 AND Order Amount <= 500)
Select distinct column1, column2 from database. Table name
Select * from database.table name order by (column name)
SELECT column1, column2, column3 FROM table ORDER BY column1 ASC, column2 DESC
SELECT Product Name, Unit Price from Products ORDER BY UnitPrice DESC LIMIT 5
SELECT column1, column2 FROM table LIMIT n OFFSET m
SELECT Orders.OrderID, Orders.OrderDate, Customers.CustomerName, Customers.Email FROM Orders JOIN Customers
SELECT EmployeeID, FirstName, LastName FROM Employees UNION SELECT EmployeeID, FirstName, LastName fro
SELECT CustomerID, CustomerName, ContactEmail from Customers UNION ALL SELECT SupplierID, SupplierName,
Usage
Can be replaced with AVG SUM Min Max
To count the number of rows in the query
To change the format of the date column and we must use alien
SQL Query
Select count (column name)
select count (*) from table
Select * from database.table name format (column date, ‘yyyy,mm,dd’)
Select * from database.table name Datediff (dd, start date, end date)
Select * from database.table name datedadd (ww, +5(-5), date)
Select concat (column1,” “, column2)
Select substring(column name, starting from, how many characters)
Select sum(column name) from database.table name order by (column name)
Select sum(column name) from database.table name group by (column name)
SELECT CustomerID, SUM(TotalPrice) AS TotalSpent from orders table GROUP BY CustomerID HAVING SUM(TotalP
SELECT ProductID, UnitPrice, Quantity, (UnitPrice * Quantity)