blitzen
10-29-2010, 10:33 AM
Can you help with a fairly complex query?
It's sorta like
WHERE family.Position = food.Position
but I need something more like
WHERE family.Position LIKE '%value.food.Position%' (I don't think that syntax exists for mySQL).
Here's an example. Notice I added fields to the generic example found everywhere on the Net.
family Table:
Field names: Position, Age, Misc
Row1: Dad, 41, ""
Row2: Mom, 45, "T1"
Row3: Daughter, 17, "T1, T2"
Row 4: "Dog, Cat", "none", "T3"
food Table:
Field names: ID, Meal, Position
Row1: T1, Steak, Dad
Row2: T2, Salad, Mom
Row3: T3, Spinach, ""
Row4: T4, Tacos, Dad
Row5: T5, Soup, Junior
The rows in "family" are tied to the rows in "food" with family.Misc and food.ID.
family.Misc can contain more than one food.ID value (comma delimited).
EXAMPLE
I want to search for "Dad" or "Junior" in the fields
family.Position, family.Age, food.Meal, food.Position
I want values from only the "family" table (SELECT family.*).
The following rows in "family" should be returned from the above example:
Row1, Row2, Row3
Row2 is returned because it's tied to row T1 in "food".
Row3 is returned because it's tied to both rows T1 and T2 in "food".
Row4 is not returned because "Dad" doesn't show up in "family" Row 4 or in "food" where ID=T3.
(Row5 table "food" is not tied to any row in "family" so it's ignored.)
Any help would be appreciated.
Thank you!
It's sorta like
WHERE family.Position = food.Position
but I need something more like
WHERE family.Position LIKE '%value.food.Position%' (I don't think that syntax exists for mySQL).
Here's an example. Notice I added fields to the generic example found everywhere on the Net.
family Table:
Field names: Position, Age, Misc
Row1: Dad, 41, ""
Row2: Mom, 45, "T1"
Row3: Daughter, 17, "T1, T2"
Row 4: "Dog, Cat", "none", "T3"
food Table:
Field names: ID, Meal, Position
Row1: T1, Steak, Dad
Row2: T2, Salad, Mom
Row3: T3, Spinach, ""
Row4: T4, Tacos, Dad
Row5: T5, Soup, Junior
The rows in "family" are tied to the rows in "food" with family.Misc and food.ID.
family.Misc can contain more than one food.ID value (comma delimited).
EXAMPLE
I want to search for "Dad" or "Junior" in the fields
family.Position, family.Age, food.Meal, food.Position
I want values from only the "family" table (SELECT family.*).
The following rows in "family" should be returned from the above example:
Row1, Row2, Row3
Row2 is returned because it's tied to row T1 in "food".
Row3 is returned because it's tied to both rows T1 and T2 in "food".
Row4 is not returned because "Dad" doesn't show up in "family" Row 4 or in "food" where ID=T3.
(Row5 table "food" is not tied to any row in "family" so it's ignored.)
Any help would be appreciated.
Thank you!