SQL Basics

It's really easy to get started with SQL even if you have never used it before.

Here's a really simple query to get you started. This selects every column * from the table customers. By default SQL will always return all rows (we'll learn how to change that later).

SELECT * FROM customers

Ok, let's say we don't want every column - we're only interested in the id and name column from our customers table.

SELECT id, name FROM customers

Oh nice, ok let's see if we can just get just the first 10 customers.

SELECT id, name FROM customers LIMIT BY 10

Great, but which customers will be the first 10? Well it's usually the first 10 rows added to the table. Let's say we want the last 10 customers created, we can use a sort so the first 10 are the most recently created customers.

SELECT id, name FROM customers LIMIT BY 10 ORDER BY created_at DESC

Pretty good so far - now lets filter customers to only include customer rows who have purchased something (assuming we have a has_purchased column in our table).

SELECT id, name FROM customers LIMIT BY 10 ORDER BY created_at DESC WHERE has_purchased == TRUE

Ok, that should be enough to get you started - but if you're looking for more, check out this full guide.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.