加入我无法弄清楚的查询问题
所以我有三个表:
Table Place: _id autoincrement not null primary key, name TEXT,place TEXT
Table Food: _id autoincrement not null primary key, food TEXT
Table Person: _id autoincrement not null primary key, personName TEXT, PLACE_ID INTEGER NOT NULL, FOOD_ID INTEGER
我想提取所有食物和地点信息,但是,如 person 表中所述,FOOD_ID 可以为空值。假设数据库已完全正确填充。我该如何查询这个?我尝试以下查询:
select * from Person,Food,Place where Place._id = Person.PLACE_ID and if not null Person.Food_id Food._id = Person.FOOD_ID
但这不起作用!
任何帮助将不胜感激!
谢谢! 乔恩
So I have three tables:
Table Place: _id autoincrement not null primary key, name TEXT,place TEXT
Table Food: _id autoincrement not null primary key, food TEXT
Table Person: _id autoincrement not null primary key, personName TEXT, PLACE_ID INTEGER NOT NULL, FOOD_ID INTEGER
I want to pull all the food and Place information however, as noted in the person table, there can be a null value for FOOD_ID. Assume the database is fully populated correctly. How do I query this? I tried to following query:
select * from Person,Food,Place where Place._id = Person.PLACE_ID and if not null Person.Food_id Food._id = Person.FOOD_ID
But that doesn't work!
Any help would be greatly appreciated!
Thanks!
Jon
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请记住,即使右表中没有匹配的行,LEFT OUTER 连接也会返回左表(本例中为 Person)中的所有行。右侧表的值全部为 NULL。
Remember, a LEFT OUTER join returns ALL rows in the left table (Person in this case) even when there are no matching rows in the right table. The values for the right side table will all be NULL.