Practice Basic SQL Commands

Also, here you’ll get SQL interview questions, exercises, examples, etc. Data is the new fuel of this world but only data is unorganized information, so to organize that data we make a database. A database is the organized collection of structured data which is usually controlled by a database management system (DBMS). Databases help us with easily storing, accessing, and manipulating data held on a computer.

Take some time to go through these before moving on to the Mid-Level SQL section. The CREATE DATABASE command creates a new database with the specified name. The SELECT command can also be used with other SQL commands such as ORDER BY, GROUP BY, and JOIN to further refine the data being retrieved.

Some of The Most Important SQL Commands

If the order is not specified (neither ASC or DESC are written), the order is set to ascending by default. Here, table_name is the name of the table you want to remove data from, and condition is the criteria for selecting which rows to remove. Keep in mind that SQL dialects vary between database engines. It’s a bit like the difference between HD DVD and Blu-ray (or VHS and Betamax).

Basic SQL commands

Now, we need to show only employees with a salary above 3,800. It’s a clause that accepts conditions and is used for filtering the output. It goes through the table and returns only the data that satisfies the condition. This ‘GROUP BY’ statement is used with the aggregate functions to group the result-set by one or more columns. It is a language for relational database management systems.

Top 5 Reasons to Learn Cassandra Decoded!

Think of it as the “OR” JOIN compared with the “AND” JOIN (INNER JOIN). RIGHT JOIN selects records from the right table that match records in the left table. A JOIN clause is used to combine rows from two or more tables.

  • The four types of JOIN are INNER, LEFT, RIGHT and FULL.
  • Optimise tables and greatly speed up queries by adding an index to a column.
  • Combine two unique queries (with the same columns) into one result.
  • ASC keyword sorts the data in ascending
    order and the DESC keyword sorts the data in descending order.

To display all details of items whose purchase quantity is more than 5 arranged in decreasing order of Date of Purchase. To display maximum cost price basis sql of the items which contain letter ‘J’ in the company name. To display all the information of those items whose name starts with letter ‘M’.

SQL Commands: Data Manipulation Language Commands (DML)

With this query, we’re building on the previous example; we want to sort the output by the employee’s salary and their last name. This time, we sort by salary descending and then by last name ascendingly. Knowing this SQL query will allow you to filter data according to numeric values. You can do that using comparison operators in the WHERE clause. All this tells us that this table is a list of a company’s employees and their salaries. All employees work in the sales division, where the department can be either Corporate or Private Individuals.

Basic SQL commands

You must create your tables before you can enter data into them. IN operator enables us to apply multiple value filters to WHERE clause. The
following query fetches the students’ data who have taken the Roman and European History lessons. WHERE clause is used to filter the data according to specified conditions.

Basic SQL commands