What are the SQL MAX() and MIN() Functions?
The MAX() function returns the largest value in the selected column.
The MIN() function returns the smallest value in the selected column.
SELECT MAX(Weight) AS LargestWeight
FROM CricketBats;
SELECT MIN(Weight) AS SmallestWeight
FROM CricketBats;
What are the SQL AVG(), COUNT() and SUM() Functions
The SQL AVG() function returns the average value in a numeric values column.
e.g.
SELECT AVG(Weight)
FROM Cricketbats;
The SQL COUNT() function returns the number of rows count that matches with a specified criteria.
SELECT COUNT(ProductID)
FROM Cricketbats;
The SQL SUM() function returns the total sum of a numeric values in a specific column.
e.g
SELECT SUM(Weight)
FROM Cricketbats;
What is SQL UPDATE Statement?
The SQL UPDATE statement is used for modifying the existing records in the selected table.
e.g as below:
UPDATE Users
SET UserContactName=’First name Last name’, City=’City1′
WHERE UserID=1;
What is SQL ORDER BY Keyword
The purpose of ORDER BY keyword is to sort the results in ascending or descending order.
example for ascending order
SELECT * FROM Users
ORDER BY State ASC;
or
SELECT * FROM Users
ORDER BY State;
example for descending order
SELECT * FROM Users
ORDER BY State DESC;
What is a NULL Value in SQL?
NULL values can not be compared using operators =, <, or <> so we will need to use the “IS NULL” or “IS NOT NULL” operators instead.
SELECT UserName, UserContactName, Address FROM Persons
WHERE Address IS NULL;
SELECT UserName, UserContactName, Address FROM Persons
WHERE Address IS NOT NULL;
What is SQL INSERT INTO Statement?
The INSERT INTO statement is used for inserting new records to a table.
e.g.
INSERT INTO Users (UserName, UserContactName, UserAddress, City, ZipCode, State, Country)
VALUES (‘Test1′,’Firstname last name’,’address 1, 2,3 ‘,’City namer’,’99999′,’Statename’,’Countryname’);
What is SQL INSERT INTO SELECT Statement?
The SQL INSERT INTO SELECT statement is used for copying data from one table and then to insert to someother table.
e.g. as below:
INSERT INTO Users (UserName, UserCity, Country)
SELECT VendorName, VendorCity, Country FROM Vendors;
What is the SQL DELETE Statement?
The SQL DELETE statement is used for deleting the existing records in the selected table.
e.g as below:
DELETE FROM Users
WHERE UserName=’Firstname1 Lastname1′;
What is AND, OR and NOT Operators in SQL
AND, OR, and NOT operators are combined with the WHERE clause to get the desired filtered results.
e.g
SELECT * FROM Users
WHERE State =’illinois’ AND City=’Chicago’;
SELECT * FROM Users
WHERE City=’Chicago’ OR City=’New York’;
SELECT * FROM Users
WHERE NOT State =’Chicago’;
What is SQL WHERE Clause?
SQL WHERE clause is used to filter records and its added as below
e.g.
SELECT States FROM Users where Usersgroup = ‘1’;
What is the SQL SELECT TOP Clause ?
The SELECT TOP clause is used to specify the number of records to return.
e.g as below:
SELECT TOP 100 * FROM Users;