Learn the Basics of Extracting Data in SQL in Five Minutes

CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

SQL Database Tutorials

Structured Query Language (SQL) is a programming language used to interact with relational databases. Using SQL, you can access, manage, or manipulate large quantities of data in a matter of seconds. This guide will teach you the basics of SQL, along with its three core clauses: SELECT, FROM, and WHERE.

What is a Relational Database (RDBMS)?

A relational database is an organized collection of data points that have defined relationships between them. Relational database management systems (RDBMS) are the bridge between relational databases and the information you wish to extract from them using SQL.

To extract data in a RDBMS, you need to know how to write an SQL statement. Your statement, or query, is what tells the database what you want from it (usually a command or a question). SQL statements are made up of a series of clauses, along with information corresponding to the database you’re using such as tables, columns, and rows.

Prior to writing a statement, you should think about what sort of data you would like to see, or what questions you want to be answered. SQL can do a lot of things, so planning ahead of time can lead to less headaches down the road!

Read: Database Programming with C/C++.

SQL Statements: SELECT, FROM, and WHERE

You may be thinking: “Let’s get into writing these statements then!” Not so fast. You need to understand the basic clauses of SQL first. The SELECT, FROM, and WHERE clauses are often considered the bread and butter of SQL.

Side note: There is a reason that I’m writing each clause in capital letters, but that is for another story. Don’t worry, it’s not that important to understand right now.

The SELECT clause indicates the data you want to select. This is specified by selecting data from individual columns within a table. You could also select all of the columns in a table by using typing “*”.

The FROM clause is used to locate where the data is coming from. This clause usually specifies which table and/or database the data is coming from.

The WHERE clause specifies the conditions you would like your data to meet. You can call out individual columns in this clause to meet certain requirements based on the data within their rows. This clause can be used with quantitative or qualitative data.

SQL Statement Examples

Imagine you are looking at sales data from the month of September. The table you are looking at is called September2021, located in your company’s sales database. You are interested in seeing all of the data from sales that were greater than $500. Your SQL statement would look like this:

FROM September2021
WHERE Sale_Amount > 500

Let us say you are looking at customer data. The table you are looking at is called Customers, located in your company’s marketing database. You are interested in seeing all of the data from customers located in the state of Connecticut. Your SQL statement would be written like this:

FROM Customers
WHERE State = “Connecticut”

SQL Statement Tutorial

Exciting stuff, isn’t it? There is so much more to SQL than its basic clauses of SELECT, FROM, and WHERE. Even the basics can have multiple layers to them! More often than not, your SQL statements will include at least one of these clauses, so it is important to know them very well.

Read: How to Load Data into an Azure SQL Database.

Anthony Fiducia
Anthony Fiducia
Anthony Fiducia is a New York based writer whose passion is bridging the gap between readers and new or complex information. When not writing, Anthony is usually found hiking, practicing his photography, or watching and studying film.

More by Author

Get the Free Newsletter!

Subscribe to Data Insider for top news, trends & analysis

Must Read