DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 968,547 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Amber-Yerkey
Amber-Yerkey

Posted on • Updated on

SQL Basics

What is SQL?

To learn the basics of SQL, we should probably first take a look at what SQL is and what it is used for.

SQL stands for Structured Query Language and can be pronounced by the letter S-Q-L or like "sequel". This language is used to pull (query) data from databases. It can also be used to create new tables or update existing ones. There are other uses when you become more familiar with it. If you're just starting out, it might be easiest to learn how to pull from tables first. It will make it easier to understand what makes a good table before jumping in.

It's also good to know that there are different versions of the SQL language. However, they all use the basic commands we'll be talking about.

To get started, you'll need a database with tables to pull from. I would recommend starting with W3Schools since they have starter tables and exercises for you to practice.

The Basics

The very basics of SQL include just 3 command words.
SELECT
FROM
WHERE

  • SELECT is our first statement that is used to select the data we need returned from the database. These will be the columns we want it to return or the columns we create based on aggregated data.

  • FROM selects the table we want to pull our data from.

  • WHERE is how we filter the data that we want returned. Any filters after WHERE will use the word AND.

SQL Basic Commands Example

In our example here, we can see that I only want 3 columns returned to me with the SELECT statement - the id, age, and height. I want to pull from data FROM the table drivers_license and I want to filter the results returned to me WHERE only the ages are over 30 AND the height is less than 60.

For SELECT, there's also the option to use 'SELECT *'. Using the asterisk will return all of the columns. However, it is good practice to just return the data that is needed. That is also why it's good to filter tables to be as specific as possible in the data that needs to be returned since when you start working with larger data sets the data that's being returned, and the amount of time and money to query that data, can get out of hand pretty quickly. Build good habits now!

Making Tables

Once you get comfortable with some of the basics on practice tables, you should jump into making practice tables as well. W3Schools also offers practice for making tables and querying them.

But didn't you just say earlier not to jump into tables? Well, learning the basics of how to create a table will actually help you make better queries! Just don't overwhelm yourself and start with the basics of a query first!

Practice, Practice!

For a fun game for practice querying - I would suggest Knight Lab SQL Murder mystery game. It's fun, free, and has a walkthrough in case you need some help.

Top comments (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.