Android 加入查询问题,我可以';不明白
所以我有三张桌子:Android 加入查询问题,我可以';不明白,android,sqlite,Android,Sqlite,所以我有三张桌子: 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
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表中所指出的,食物ID可能有一个空值。假设数据库完全正确填充。我如何质疑这一点?我试图回答以下问题:
select * from Person,Food,Place where Place._id = Person.PLACE_ID and if not null Person.Food_id Food._id = Person.FOOD_ID
但那不行
任何帮助都将不胜感激
谢谢!
乔恩
请记住,即使右表中没有匹配的行,左外部联接也会返回左表中的所有行(本例中为Person)。右侧表的值都将为空。如果我们只想选择某人的名字,比如Jon,该怎么办?
SELECT *
FROM Person p
INNER JOIN Place pl
ON p.PLACE_ID = pl._id
LEFT OUTER JOIN Food f
ON p.FOOD_ID = f._id