SQL: Select Tables & Ninja Turtles

Sam Lesser
4 min readJun 13, 2021
Assemble the crew 🐢 🐢 🐢 🐢

Introduction

Hello fellow reader. I see you’ve stumbled upon my super cool blog about updating tables with SQL. I’ll go through a simple select statement and take it apart line by line. I find this technique allows us to further understand what we are writing to the database and why it works.

In case you aren’t familiar with SQL or what a table is, I’ve got you covered. Click on the links below for more details on the topic.

a fine selection of local & handcrafted blogs...

- Creating a Table: https://ineedmoreplates.medium.com/create-sql-tables-panda-memes-8f10973a3859- Inserting into a Table: https://ineedmoreplates.medium.com/sql-insert-into-a-table-parrot-memes-a355232e81b1

Let’s dive in 🐋

For the purposes of explaining this concept, let’s imagine we have access to a Teenage Mutant Ninja Turtle Database. This Database holds tons of information regarding everyone’s favorite TV show. Yet’s pretty expensive and impractical to pull all the information or “data” from this source.

Let’s suppose I only wanted to pull information about the four turtles themselves. I need this data to show up on the front end of my application and I’d like it organized by each unique character. How can I pull information only regarding the four turtles?

Assuming all this information is stored in one place we would have to write an SQL statement using SELECT.

Our code:

SELECT * FROM turtles;------------------------------
syntax:
SELECT * FROM table_name;

Pretty cool, but what does it do? Well, the SELECT keyword is telling the database you’d like to grab read something from the database. The “*” means you want to read every column. While the FROM + table_name is telling the database which table it should read from.

Our code

SELECT * FROM turtles;SELECT -->           I want to read ...
* --> ...Everything...
FROM --> ...from the...
turtles --> ...turtles table!

What if we are picky?

Cool beans 😎 , but what if I only needed the name, weapon, and favorite pizza topping of each turtle? Well assuming it’s already in the database and stored under each turtle we could write something like this…

Our codeSELECT name, weapon, fav_pizza FROM turtles;-------------------------------------------syntaxSELECT column1, column2,... FROM table_name;

Notice how we didn’t use our shortcut… *… but instead wrote in the name of each column. This how we tell the database we only want data from the “turtles” table’s columns and we explicitly name those columns. SQL requires us to be very precise about how we ask for things. Which is part of the reason why databases are so efficient! As developers, we FIRST need to know exactly what kind of data we want AND know where it lives in the database!

Conclusion

You’re not alone, Micheal Angelo! 🐢 🥷 🍕 😢

Congrats 🎊 ! You now know how to grab data from a database using SQL. Pretty cool right? I’d like to point out that, these are very simple and easy-to-understand explanations about SQL. In real-life situations, SQL statements can very quickly become much more complex. I’d encourage you to do some additional research on the matter, it’s only the tip of the iceberg here.

Thank you for taking the time to read this blog. If you found it helpful please give me a few claps. Stay Tuned 📺 , I’ll be creating another SQL blog topic in the near future. See you soon & happy coding 🧑‍💻

Links

SQL Select: https://www.w3schools.com/sql/sql_select.asp

--

--

Sam Lesser

Career Changer, Software Engineer & Web Developer