Build Your Own AI Assistant Part 1 - Creating the Assistant
116820 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
114678 Views
Control Arduino with Python using Firmata / PyFirmata
87081 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
57314 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
53588 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
52067 Views
LidarBot
Snaszy NAS a 3D printed NAS for Raspberry Pi
Waveshare CM5 boards
The Best Arduino Robot for Beginners
SMARS Lab upgrade with PyCharm
Chicken Nugget Piano
Mini-Rack 3D Design Tutorial
0h 20m
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
42% Percent Complete
By Kevin McAleer, 6 Minutes
In this lesson, we’ll cover the SELECT statement, which is the cornerstone of querying data in SQL. You’ll learn how to retrieve data from tables, apply basic filters, and sort your results.
SELECT
The SELECT statement is used to retrieve specific data from one or more tables. You can use SELECT to display specific columns, filter rows, sort results, and perform calculations.
SELECT column1, column2, ... FROM table_name;
Example: Display all columns from the users table.
users
SELECT * FROM users;
Example: Display only the name and email columns.
name
email
SELECT name, email FROM users;
The * symbol selects all columns in the table, while specifying individual columns limits the output to just those columns.
*
WHERE
The WHERE clause allows you to filter rows based on specified conditions. It’s used to retrieve only the data that meets certain criteria.
SELECT column1, column2, ... FROM table_name WHERE condition;
Example: Retrieve all users with the name “Alice”.
SELECT * FROM users WHERE name = 'Alice';
Example: Retrieve users who are 30 years old or older.
SELECT * FROM users WHERE age >= 30;
=
WHERE age = 30
<>
!=
WHERE name != 'Alice'
<
WHERE age < 25
<=
WHERE age <= 30
>
WHERE age > 25
>=
WHERE age >= 30
BETWEEN
WHERE age BETWEEN 20 AND 30
LIKE
WHERE name LIKE 'A%'
IN
WHERE age IN (25, 30, 35)
Tip: Use LIKE with wildcards (% and _) for flexible pattern matching. % matches any sequence of characters, while _ matches a single character.
%
_
ORDER BY
The ORDER BY clause sorts the result set by one or more columns in ascending (ASC) or descending (DESC) order.
ASC
DESC
SELECT column1, column2, ... FROM table_name ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;
Example: List all users, sorted by age in ascending order.
SELECT * FROM users ORDER BY age ASC;
Example: List all users, sorted by age in descending order.
SELECT * FROM users ORDER BY age DESC;
Example: Sort by age, and then by name within each age group.
SELECT * FROM users ORDER BY age ASC, name ASC;
LIMIT
The LIMIT clause restricts the number of rows returned by the query. This is especially useful when testing queries or when only the top results are needed.
SELECT column1, column2, ... FROM table_name LIMIT number_of_rows;
Example: Retrieve the first 5 users.
SELECT * FROM users LIMIT 5;
LIMIT can be used with ORDER BY to retrieve the top or bottom values.
Example: Retrieve the 3 oldest users.
SELECT * FROM users ORDER BY age DESC LIMIT 3;
AND
OR
You can combine multiple conditions in the WHERE clause using AND and OR operators to refine your queries.
Example: Retrieve users who are over 25 years old and whose name starts with “A”.
SELECT * FROM users WHERE age > 25 AND name LIKE 'A%';
Example: Retrieve users whose name is “Alice” or who are 30 years old.
SELECT * FROM users WHERE name = 'Alice' OR age = 30;
AS
Aliases give temporary names to columns or tables for easier readability. They do not change the actual column or table names in the database.
Example: Display user names with the alias “User Name”.
SELECT name AS "User Name" FROM users;
Example: Use an alias for the users table to shorten query syntax.
SELECT u.name, u.age FROM users AS u WHERE u.age > 25;
Retrieve all users from the users table, displaying only the name and email columns.
Retrieve all users whose age is between 20 and 30.
SELECT * FROM users WHERE age BETWEEN 20 AND 30;
Retrieve the top 3 users by age, in descending order.
Retrieve users whose name starts with “A” and display their names as “User”.
SELECT name AS "User" FROM users WHERE name LIKE 'A%';
Here’s a recap of the techniques covered in this lesson:
ORDER BY age DESC
LIMIT 5
WHERE age > 25 AND name LIKE 'A%'
SELECT name AS "User Name"
With these querying techniques, you’re now equipped to retrieve and filter data from your tables effectively. In the next lesson, we’ll expand on filtering techniques and introduce conditional logic for more powerful queries.
< Previous Next >