So I have three tables:
Table Place: _id autoincremen开发者_运维技巧t 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
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
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.
精彩评论