Sqlite3 select from several "where" tables

I am trying to query multiple tables at once. Let's say I have a table called PRESCHOOLERS, and I have another one called FAVORITE_GOOEY_TREATS, with a foreign key column in the PRESCHOOLERS table referencing the id field of FAVORITE GOOEY TREAT. What would I do if I wanted to get a list of preschoolers with their names along with their favorite treats. I mean something like:

first_name    |    treat
john          |  fudge
sally         |  ice-cream

Here is what I am trying, but I have a syntax error in that part.

SELECT PRESCHOOLERS.first_name, FAVORITE_GOOEY_TREATS.name as treat
FROM PRESCHOOLERS, FAVORITE_GOOEY_TREATS
WHERE PRESCHOOLERS.favorite_treat = FAVORITE_GOOEY_TREATS.id and PRESCHOOLERS.age>15;

As far as I know, this is similar to sql standards, but sqlite3 doesn't really like it. Can someone point me to some examples of similar queries that work?

+5
source share
1

Try

SELECT PRESCHOOLERS.first_name, FAVORITE_GOOEY_TREATS.name as treat
FROM PRESCHOOLERS
JOIN FAVORITE_GOOEY_TREATS ON PRESCHOOLERS.favorite_treat = FAVORITE_GOOEY_TREATS.id
WHERE PRESCHOOLERS.age > 15;
+9

All Articles