Tip:
Highlight text to annotate it
X
Let's talk a little bit about SQL, or "sequel," or structured query language.
SQL is a language.
It's not quite a programming language, but it's a language for expressing queries,
and so you would use SQL on a relational database
to ask questions of the database to get that out of it,
so MySQL, postgreSQL, SQLite.
Obviously they all have SQL in the name, and they all use SQL for
putting data into the database and getting data out.
It was invented in the 1970s,
which was long before the internet existed or the Web existed
or web applications even existed,
so SQL was designed to solve problems that
are very much different from the problems you'll be solving
building a consumer web application.
There's still a lot of very important parts to SQL,
and we'll be discussing the major pieces today
so you can know how to use them, but just keep in mind that
SQL and relational databases have existed long before the Web,
and so there are some things that aren't exactly relevant.
SQL looks a little something like this.
This is a basic SQL query,
and what this says is select,
which basically means retrieve data, *,
this means all columns, from links, this is the table
that we're fetching data from, where, ID = 5,
and this is a constraint.
SQL, as you can see, it's a fairly readable language.
Select all from links where ID = 5.
That's almost similar to the quiz I gave you earlier in this lesson.
There are a couple parts of this line that are relevant.
This first section, the select *,
this is basically what we're selecting.
The can--instead of being a--can actually be a list of columns,
but for a lot of things we're going to be doing, we'll be selecting all of the columns.
But if you don't want all of the columns, let's say you just wanted
just the URL from the links, it might look something like this:
select url, and you could put a comma, select url, title
if you wanted to select just the URL and the title.
But we'll be using * for now.
Now from, this is the from clause right here.
This is where we're going to fetch the data from,
so we've only talked about really one table, our links table,
and in my example, that's what I'm going to use.
But you can actually include any table of your making or multiple tables,
and we'll talk briefly about what that means a little bit later,
but for now, we're just going to be selecting from the links table,
and that's the name of the table we made.
Where, now the rest of the SQL, or the rest of the SQL you can see here,
this is the where clause, and these are the constraints.
These are which rows from our table to return,
and this is actually a really interesting part of the statement here.
We can actually put quite a lot in here.
Let's play around with this a little bit in the IDE and see how it works.