我正在尝试一次查询多个表.假设我有一个名为PRESCHOOLERS的表,我有一个名为FAVORITE_GOOEY_TREATS的表,在PRESCHOOLERS表中引用了一个外键列,引用了FAVORITE GOOEY TREAT的id字段.如果我想获得一份带有他们的名字和他们最喜欢的零食的学龄前儿童名单,我该怎么办?我的意思是:
first_name | treat john | fudge sally | ice-cream
这是我正在尝试的,但我在where部分有语法错误.
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;
尝试
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;