Retrieving Data: SELECT and FROM

Welcome to SQL Movie Explorer

Mastering the Basics

SQL (Structured Query Language) is the standard language for communicating with databases. In this lesson, you'll learn how to use the SELECT and FROM clauses to retrieve data from a movie database.

Welcome to your first step in mastering SQL! In this lesson, you will learn how to communicate with a database to pull exactly the information you need. Whether you are looking for a specific movie title or a full list of cinema history, the SELECT and FROM clauses are your primary tools.

Welcome to the Movie Database

The Relational Database

Before we write code, let's look at our data. A relational database organizes information into tables, similar to a spreadsheet.

Welcome to your first step in data analysis! To work with data, you first need to know how it's organized. Think of this Movie database as a collection of organized tables. These are rows. Each row is a single, unique record—in this case, one specific movie like 'The Matrix'. These are columns. They define the 'categories' of information we have, like the movie's title or the year it was released.

The Foundation: SELECT and FROM

The SQL Syntax

To retrieve data, you need two fundamental clauses:

Always end your query with a semicolon (;).

Every basic SQL query requires two main parts. First, the SELECT clause tells the database exactly which columns you want to see. The FROM clause tells the database where to look. Since we are interested in films, our table name is 'Movie'. When you write SELECT, you are choosing your ingredients. If you want titles, you'll list the 'Title' column here.

The Anatomy of a Table

Relational Database Basics

Data is stored in tables, which look like digital spreadsheets. Tables consist of columns (categories) and rows (individual records).

Think of a table like a digital spreadsheet. It is made up of columns, which are categories like Title or Year, and rows, which are the individual movie records like 'The Matrix'. In this course, we will work with a table named 'Movie'.

Exercise: Pick Your Columns

Write Your First Query

Retrieve just the Title and Year from the Movie table.

Remember to separate columns with a comma and end with a semicolon.

It's your turn. In the editor, write a query to pull only the 'Title' and 'Year' columns from our Movie table.

The SELECT and FROM Clauses

The Core Syntax

Every basic SQL query requires two main parts:

Every basic SQL query requires two main parts. SELECT tells the database which columns you want to see, while FROM tells the database which table contains those columns. It's like asking a librarian for a specific chapter from a specific book.

The Asterisk (*) Wildcard

The Shortcut

If you need to see all columns in a table, you don't have to type them all out. Use the asterisk (*) wildcard.

SELECT * FROM Movie;

Sometimes you want the whole picture. Instead of typing every single column name, you can use the asterisk—the star symbol. In SQL, the asterisk acts as a shortcut for 'everything'. SELECT star FROM Movie will return every column and every row in that table.

Practice: Selecting Specific Columns

Try it Yourself

Write a query to retrieve only the Title and Year from the Movie table.

Remember to separate columns with a comma and end with a semicolon.

Let's put this into practice. Type a query to retrieve the 'Title' and 'Year' columns from the 'Movie' table. I'll check your syntax when you're done.

Exercise: See Everything

Retrieve the Entire Catalog

Write a query using the wildcard to retrieve all information from the Movie table.

Let's see the full catalog. Use the shortcut you just learned to retrieve all columns from the Movie table.

Practice: The Wildcard Query

Your Turn

Write a query to retrieve all information for every movie in the database using the wildcard.

Now, try to write a query that pulls all the data from the Movie table at once. Use the wildcard shortcut we just discussed.

Spot the Errors

Common Pitfalls

SQL is strict about syntax. Look at the code on the right and click on the errors you see.

Watch out! Even pros make mistakes. Look at these queries and click on the specific parts that will cause an error. Actually, that part is correct. Look closer at the commas or the spelling of the column names. Great catch! That comma/typo would definitely break the query. SQL requires precision.

The SQL Detective

Find the Error

One of your colleagues wrote this query, but it's returning an error. Can you identify and fix it?

SELECT Title Year FROM Movie

Look closely at this query. It's missing two small but vital pieces of syntax. Can you fix it so it runs correctly?

Lesson Summary

Great Job!

You've learned the foundation of SQL querying. You can now retrieve specific data or entire tables using SELECT and FROM.

Fantastic work! You've mastered the basics of data retrieval. You now know how to tell a database exactly what you want and where to find it. Next, we'll learn how to filter those results to find specific records using the WHERE clause.