Sql Commands List With Example Pdf

In the era where data is being generated in humongous amounts, there is a constant need to handle data in databases. Relational databases are one of the most popular databases, and SQL is the basis of relational databases. Therefore are indispensable in most of the job roles. NOTE: You can also combine the above three operators and write a query as follows:SELECT. FROM EmployeeInfoWHERE NOT Country='India' AND (City='Bangalore' OR City='Hyderabad');BETWEEN OperatorThe BETWEEN operator is used, when you want to select values within a given range. Since this is an inclusive operator, both the starting and ending values are considered. Syntax SELECT ColumnName(s)FROM TableNameWHERE ColumnName BETWEEN Value1 AND Value2; ExampleSELECT.

Sql Commands List With Example Pdf Maker

FROM EmployeeSalaryWHERE Salary BETWEEN 40000 AND 50000;LIKE OperatorThe LIKE operator is used in a WHERE clause to search for a specified pattern in a column of a table. There are mainly two wildcards that are used in conjunction with the LIKE operator:.% – It matches 0 or more character. – It matches exactly one character.Syntax SELECT ColumnName(s)FROM TableNameWHERE ColumnName LIKE pattern;Refer to the following table for the various patterns that you can mention with the LIKE operator. NOTE: You can also use IN while writing Nested Queries. EXISTS OperatorThe EXISTS operator is used to test if a record exists or not.

Syntax SELECT ColumnName(s)FROM TableNameWHERE EXISTS(SELECT ColumnName FROM TableName WHERE condition); ExampleSELECT EmergencyContactNameFROM EmployeeInfoWHERE EXISTS (SELECT EmergencyContactName FROM EmployeeInfo WHERE EmployeeId = 05 AND City = 'Kolkata');ALL OperatorThe ALL operator is used with a WHERE or and returns TRUE if all of the subquery values meet the condition. Syntax SELECT ColumnName(s)FROM TableNameWHERE ColumnName operator ALL(SELECT ColumnName FROM TableName WHERE condition); ExampleSELECT EmployeeNameFROM EmployeeInfoWHERE EmployeeID = ALL (SELECT EmployeeID FROM EmployeeInfo WHERE City = 'Hyderabad');ANY OperatorSimilar to the ALL operator, the ANY operator is also used with a WHERE or and returns true if any of the subquery values meet the condition. Syntax SELECT ColumnName(s)FROM TableNameWHERE ColumnName operator ANY(SELECT ColumnName FROM TableName WHERE condition); ExampleSELECT EmployeeNameFROM EmployeeInfoWHERE EmployeeID = ANY (SELECT EmployeeID FROM EmployeeInfo WHERE City = 'Hyderabad' OR City = 'Kolkata');Next, in this article on SQL Commands, let us look into the various Aggregate Functions provided in SQL.

Sql Commands List With Example Pdf Word

Sql Commands List With Example Pdf

List Of All Sql Commands With Example Pdf

Aggregate FunctionsThis section of the article will include the following functions:.MIN FunctionThe MIN function returns the smallest value of the selected column in a table. Syntax SELECT MIN(ColumnName)FROM TableNameWHERE Condition; ExampleSELECT MIN(EmployeeID) AS SmallestIDFROM EmployeeInfo;MAX FunctionThe MAX function returns the largest value of the selected column in a table. Syntax SELECT MAX(ColumnName)FROM TableNameWHERE Condition; ExampleSELECT MAX(Salary) AS LargestFeesFROM EmployeeSalary;COUNT FunctionThe COUNT function returns the number of rows which match the specified criteria.

Syntax SELECT COUNT(ColumnName)FROM TableNameWHERE Condition; ExampleSELECT COUNT(EmployeeID)FROM EmployeeInfo;SUM FunctionThe SUM function returns the total sum of a numeric column that you choose. Syntax SELECT SUM(ColumnName)FROM TableNameWHERE Condition; ExampleSELECT SUM(Salary)FROM EmployeeSalary;AVG FunctionThe AVG function returns the average value of a numeric column that you choose. Syntax SELECT AVG(ColumnName)FROM TableNameWHERE Condition; ExampleSELECT AVG(Salary)FROM EmployeeSalary;NULL FunctionsThe NULL functions are those functions which let you return an alternative value if an expression is NULL. In the SQL Server, the function is ISNULL. ExampleSELECT EmployeeID.

(MonthYearofSalary + ISNULL(Salary, 0))FROM EmployeeSalary. NOTE: When you use ROLLBACK with SAVEPOINT, then you can directly jump to a savepoint in an ongoing transaction. Syntax: ROLLBACK TO SavepointName; SAVEPOINTThis command is used to temporarily save a transaction. So if you wish to rollback to any point, then you can save that point as a ‘SAVEPOINT’. Syntax SAVEPOINT SAVEPOINTNAME;Consider the below example to understand the working of transactions in the database.

Sql commands pdf with examples free download

SQL is incredibly powerful, and like every well-made development tool, it has a few commands which it’s vital for a good developer to know. Here are a few of the most important ones – each of these queries is consequential to almost every system that interacts with an.Check this video to learn about every SQL query:Improve your skills with SQL trainer (for beginner and advanced developers)1. SQL Query for Retrieving TablesThis query can be run to retrieve the list of tables present in a database where the database is “MySchema”.SELECT. FROM MySchema.Tables;2.This is perhaps the most widely used SQL queries examples.

Posted :