Question
'joining' tables without actually grabbing the data?
I'm not quite sure how to word this question, so I'll use an
example:
I have two tables:
FOOD TYPE
---------------
Type | ID
---------------
Fruit | 1
Meat | 2
Grain | 3
FOOD ITEM
---------------
Item | TypeID
---------------
Banana | 1
Apple | 1
pork | 2
beef | 2
---------------
What I want to do is grab all the items from table 1 that have one or more
related items in table 2. So, in the above example, I want to return:
Fruit
Meat
I can do a join, but then end up with something like this:
Fruit, Banana
Fruit, Apple
Meat, pork
Meat, beef
Is there a way to accomplish this from within the SQL query itself? (Rather
than having to loop through the duplicate records returned from the join).
-Darrel
I have two tables:
FOOD TYPE
---------------
Type | ID
---------------
Fruit | 1
Meat | 2
Grain | 3
FOOD ITEM
---------------
Item | TypeID
---------------
Banana | 1
Apple | 1
pork | 2
beef | 2
---------------
What I want to do is grab all the items from table 1 that have one or more
related items in table 2. So, in the above example, I want to return:
Fruit
Meat
I can do a join, but then end up with something like this:
Fruit, Banana
Fruit, Apple
Meat, pork
Meat, beef
Is there a way to accomplish this from within the SQL query itself? (Rather
than having to loop through the duplicate records returned from the join).
-Darrel