Search⌘ K
AI Features

Solution Review: Write a Generalized Query

Explore how to write generalized SQL queries with nested SELECT statements that retrieve data based on criteria such as first and last names. Learn how constructing queries properly aids in preventing attacks like SQL injection by filtering data securely and improving defensive coding practices.

Solution: a nested query querying person

MySQL
SELECT CreatedTimestamp, Body
FROM journal_entries
WHERE PersonId =
(SELECT PersonId
FROM person
WHERE FirstName = "Frankie" AND LastName = "Manning");

Explanation

Let’s take a look at what makes up this SQL statement. We’ve already seen the first 3 lines in the ...