Categories
IT Education

SQL Tutorial

However, one of the reasons SQL is so powerful is that it allows us to pull data from multiple tables in the same query. One more thing to note — as your queries add more commands and get more complicated, you may find it easier to read if you separate them onto multiple lines. This, like capitalization, is a matter of personal preference. It doesn’t affect how the code runs (the system just reads the code from the beginning until it reaches the semicolon), but it can make your queries clearer and easier to follow.

basis sql

The remaining operations – creating, updating and deleting data – are explained in another course, Operating on Data in SQL. The tables are joined exactly the same way as in the previous example. What’s shown in the brackets can be omitted in the query and the join will work without it.

What kind of jobs can SQL get me?

It also means we can perform further analysis and visualization on the data we pull from the database, although that will be beyond the scope of this tutorial. In this article, we covered the basic SQL queries that can be used to perform simple data tasks. However, SQL offers many more clauses and techniques that allow you to do more operations on data. In this article, we’ll show you the most basic SQL queries. You can easily modify these SQL queries and use them on your own database.

basis sql

These will give you a strong foundation to build on as you continue your SQL journey. To tell the database how the orders and customers tables are connected, we use JOIN and ON. JOIN specifies which tables should be connected and ON specifies https://deveducation.com/ which columns in each table are related. SQL also includes a way to answer this question in a single query, using the GROUP BY command. As we can see, this query returned 14 different trips, each with a duration of 9990 seconds or more.

Selecting Two Columns and Filtering Using an Equality Condition in WHERE

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. It’s common to sort data by two or more columns, which you’re probably already familiar with as an Excel or Google Sheets user. To select two columns, you need to write their names in SELECT. The important thing is that the columns need to be separated by a comma. You can see in the example that there’s a comma between the columns first_name and last_name.

basis sql

This function will provide coders with the sum of all data in a column of their choosing. In addition to retrieving and analyzing data, SQL allows users to manipulate the information within a database. Generally, manipulating data refers to inserting, updating or deleting data. You can use SQL to adjust the information present in a database to be more accurate and up-to-date. The commands to do so are relatively simple (“UPDATE” and “DELETE” illustrate this) which makes the process of changing existing data relatively easy and straightforward.

Continue Learning Basic SQL Queries!

In this example, we will want to use JOIN on whichever table we didn’t include in the FROM command. So we can either use FROM orders INNER JOIN customers or FROM customers INNER JOIN orders. Our bike-sharing database contains a second table, stations. The stations table contains information about every station in the Hubway network and includes an id column that is referenced by the trips table. Let’s walk through exactly how to write a query to answer our question of whether registered or casual users take longer trips.

basis sql

This creates a new record in the table which is a new row. It gives the table a name, and the different columns we want our table to have are also passed in. Each topic is covered clearly and concisely with many practical examples that help you truly understand the concept and apply it to solve the data basis sql challenges more effectively. This SQL tutorial helps you get started with SQL quickly and effectively through many practical examples. No, there’s no need to make your own examples, like we did here. The output shows all five employees whose sales were above $5,000 in the last three months of 2022.