The below example would return the number of rows for each name, but only for names with more than 2 records. BETWEEN filters your query to return only results that fit a specified range. SELECT TOP only returns the top x number or percent from a table. This website provides tutorials with examples, code snippets, and practical insights, making it suitable for both beginners and experienced developers. CASE statements are used to create different outputs (usually in the SELECT statement).

Basic SQL commands

Below, we’ll list the main integrity constraints with brief descriptions and examples. Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical and non-technical subjects. As an example, let us try to display all the records from the CUSTOMERS table, where the SALARY starts with 200.

What is a Database? Definition, Types and Components

This allows you to specify multiple values in a WHERE clause. The USE statement is used to select the database on which you want to perform operations. When you use this statement, complete information present in the database will be lost. FULL JOIN selects records that have a match in the left or right table. Think of it as the “OR” JOIN compared with the “AND” JOIN (INNER JOIN).

Basic SQL commands

There are numerous companies around the globe seeking SQL professionals, and they pay high packages. The average salary of SQL developers is around 40,000–65,000 INR. In this section, we have listed some of the top giant companies that hire SQL experts. Views makes easier for anyone to access the information they need, without getting bogged down in complicated queries. Views also act like a helpful security guard, keeping the most sensitive information in the back room, while still allowing access to what’s needed. The content provided on, including but not limited to code and examples, is intended for educational and informational purposes only.

The ‘CREATE VIEW’ statement

This will retrieve rows where the employee_id is the same in both instances. The query above performs a CROSS JOIN between the employees and departments tables. In the query above, we’re updating the employee_name column to John Doe and the department column to Marketing in a table called employees. In the query above, value Mary is inserted into the first_name column and value Doe is inserted into the last_name column of a table called customers. The AVG command calculates the average of a column’s numeric values.

Due to its efficiency and adaptability, SQL has consistently been a valuable tool for developers, data analysts, and businesses alike. Therefore, learning SQL can be beneficial if you wish to join the tech workforce. A view in SQL is a single table, which is derived from other tables. So, a view contains rows and columns similar to a real table and has fields from one or more table. This statement goes through all the conditions and returns a value when the first condition is met. So, if no conditions are TRUE, it returns the value in the ELSE clause.

SQL Cheat Sheet: A Comprehensive Guide to SQL Commands and Queries

It allows you to define what data you want your query to return. DCL commands are used to grant and take back authority from any database user. The WITH clause is also known as common table expression (CTE) and subquery factoring. LIKE is a special operator used with the WHERE clause to search for a specific pattern in a column. IS NULL and IS NOT NULL are operators used with the WHERE clause to test for empty values.

  • This constraint ensures that all the values in a column satisfy a specific condition.
  • SQL basic commands are straightforward and declarative expressions.
  • And in this section, we have listed all the points that one has to learn while learning SQL.
  • The four basic SQL commands are SELECT, INSERT, UPDATE, and DELETE.
  • With integrity constraints, you specify which types of data can be entered into the table.

This operator displays all those records which satisfy any of the conditions separated by OR and give the output TRUE. This operator is used to filter records that rely on more than one condition. This operator displays the records, which satisfy all the conditions separated by AND, and give the output TRUE. This statement is used to modify the records already present in the table. This constraint consists of a set of default values for a column when no value is specified.

Semicolon after SQL Statements?

The IF() function evaluates a condition and returns a value based on the evaluation. The SUM command is used to calculate the sum of all values in a specified column. The TRUNCATE command is used to delete the data inside a table, but not the table itself. In this example, we’re deleting rows from the employees table where the employee_name is John Doe.

Basic SQL commands

As an example, first we will show you a SELECT statement and results without a WHERE statement. Then we will add a WHERE statement that uses all five qualifiers above. Here is a list of basic SQL commands (sometimes called clauses) you should know if you are going to work with SQL. Some database systems require a semicolon at the end of each SQL statement. In this tutorial we will use the well-known Northwind sample database
(included in MS Access and MS SQL Server).


And in this section, we have listed all the points that one has to learn while learning SQL. SQL joins serve as the weaver’s tool, allowing you to seamlessly merge data from multiple tables based on common threads. Basically, these structure functions is very similar to spreadsheets, which store data in very organized grid format.

Basic SQL commands

The first step to storing the information electronically using SQL includes creating database. And in this section we will learn how to Create, basic database queries Select, Drop, and Rename databases with examples. The COALESCE() function returns the first non-null value from a list of values.

The following code has a query, which will DELETE a customer, whose ID is 6. Now, let’s move on to the last section of this article on SQL Commands i.e. the Transaction Control Language Commands. This command is used to withdraw the user’s access privileges given by using the GRANT command.

Basic SQL commands