The query is the same as the last one, only this time we use the AVG() function, as we want to calculate the average salary by department. However, we want to show only those employees whose salaries are either above $5,000 or below $3,000. We do that by using basis sql the logical operator OR and the comparison operators in WHERE. We use this query to select the employee’s first name, last name, and salary from the table employees. When the salary is the same (green rows), the data is ordered alphabetically by last name.

Basic SQL commands

At the end of the Quiz, your total score will be displayed. No, there’s no need to make your own examples, like we did here. But we already did that for you in our SQL Basics course. The tables are joined exactly the same way as in the previous example. We tweaked the previous query to show the decrease in sales between the third and the fourth quarter.

SQL interview questions

CREATE DATABASE creates a new database, assuming the user running the command has the correct admin rights. CREATE can be used to set up a database, table, index or view. SELECT DISTINCT only returns data that is distinct — in other words, if there are duplicate records, it will return only one copy of each. For example, in the code below, we’re selecting a column called name from a table called customers.

We can say that data tables are the main objects of the databases because they are holding the data in the relational databases. It is used to specify the columns on which the two tables will be joined. Usually, those are the columns that store the same data in both tables. In other words, we join the tables on the primary and foreign keys.

Q. Fetch the first 8 rows of the albums table.

SQL is a standard database language used to access and manipulate data in databases. SQL was developed by IBM Computer Scientists in the 1970s. By executing queries SQL can create, update, delete, and retrieve data in databases like MySQL, Oracle, PostgreSQL, etc. Overall SQL is a query language that communicates with databases. The GROUP BY statement groups rows with the same values into summary rows.

The statement is often used with aggregate functions. For example, the code below will display the average age for each name that appears in our customers table. A  table is a database object that allows us to keep data through columns and rows.

A FULL OUTER JOIN returns all rows for which there is a match in either of the tables. So if there are rows in the left table that do not have matches in the right table, those will be included. Also, if there are rows in the right table that do not have matches in the left table, those will be included. An aggregate function performs a calculation on a set of values and returns a single result. The data in RDBMS is stored in database objects called tables. A table is a collection of related data entries and it consists of columns and rows.