1. Home
  2. Explore
  3. Computer Science
  4. SQL Basics

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

SQL Basics

Speaker 1Speaker 2

SQL Basics

4:26
0:00-4:26
  1. Anna

    So Michael, let's talk about SQL. It stands for Structured Query Language, and it's basically the language we use to talk to databases. Think of it as the love language of databases.

  2. Michael

    I like that. And it's everywhere—if you work in IT, cloud engineering, or pretty much any tech job, you'll run into it. I used it all the time as an AWS cloud engineer.

  3. Anna

    Exactly. And while databases can seem intimidating, they're really just like organized Excel spreadsheets. You've got columns—or fields—and rows—or records. That data lives in tables.

  4. Michael

    Right, and for big data, like a coffee shop's customer and order info, you wouldn't use Excel. You'd use a database management system, or DBMS. There are lots of them: MySQL, Microsoft SQL Server, PostgreSQL, Oracle.

  5. Anna

    And here's the great part: SQL is a standard ratified by ISO, so once you learn it, you can work with most databases. There are some nuances, but the concepts carry over.

  6. Michael

    Now, there are two main types of databases: relational and non-relational. We're focusing on relational—that's where tables are connected, or related, to each other. For example, an order table might reference a customer ID from a customer table.

  7. Anna

    Non-relational, or NoSQL, is a different beast—unstructured data. But for now, we'll stick with the relational model. Let's get hands-on. We'll install MySQL on Ubuntu.

  8. Michael

    First, update your packages with sudo apt update, then install MySQL server with sudo apt install mysql-server -y. After that, check it's running with sudo systemctl status mysql. You should see active and running.

  9. Anna

    To access the MySQL prompt, just type sudo mysql. That gets you in. And every MySQL command ends with a semicolon. Let's start by seeing what databases exist with SHOW DATABASES;

  10. Michael

    Now we'll create our own database for a coffee shop: CREATE DATABASE nc_coffee; Then USE nc_coffee; to start working with it. If you do SHOW TABLES; it'll be empty—no tables yet.

  11. Anna

    Time to create a table. For our coffee table, we need columns: ID (integer), name (string/varchar), region (string), and roast (string). We'll do CREATE TABLE coffee_table (id INT, name VARCHAR(255), region VARCHAR(255), roast VARCHAR(255));

  12. Michael

    After that, you can describe the table with DESCRIBE coffee_table; to see the columns. Now let's insert some data: INSERT INTO coffee_table VALUES (1, 'Default Route', 'Ethiopia', 'Light');

  13. Anna

    To see what's in the table, use SELECT * FROM coffee_table; That asterisk means 'all columns'. You'll see the row you just added. It's that simple—you've created a database, a table, and inserted data.

  14. Michael

    Now let's query more specifically. If you only want names, do SELECT name FROM coffee_table; And to filter, add WHERE. For example, SELECT * FROM coffee_table WHERE region = 'Ethiopia'; gives you only the Ethiopian coffees.

  15. Anna

    You can combine filters with OR: WHERE origin = 'Earth' OR origin = 'Asgard'. Or use less than: WHERE age < 30. There's also NOT: WHERE NOT origin = 'Earth'. That's the power of SQL—you can pinpoint exactly the data you need.

  16. Michael

    What about deleting and updating? Say an imposter named Jeff snuck into our customer table. DELETE FROM customers WHERE first_name = 'Jeff'; removes him. To update, say UPDATE customers SET last_name = NULL WHERE first_name = 'Groot';

  17. Anna

    And you can sort results: SELECT * FROM customers ORDER BY age ASC; for youngest to oldest, or DESC for oldest to youngest. That's really handy.

  18. Michael

    What if you need to add a new column after the table is already created? Use ALTER TABLE: ALTER TABLE customers ADD COLUMN beard BOOLEAN; Then update each row with beard = TRUE or FALSE.

  19. Anna

    Now, we haven't covered everything. There's more like primary keys, foreign keys, joins, and views. Those let you connect tables and pull data from multiple sources. For example, 'How many times did Spider-Man order the dark roast?' That requires relationships.

  20. Michael

    But what we've covered here is enough to make you dangerous. You know what a database is, how to create one, insert, select, update, delete, filter, sort, and alter tables. That's a solid foundation to build on.

  21. Anna

    Exactly. And if you want to go deeper, topics like joins and views are the next step. But for now, pat yourself on the back—you've just learned the basics of SQL.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent