|
|
Subject:
SQL Query for sql junkies
Category: Computers > Programming Asked by: vishalhemant-ga List Price: $2.50 |
Posted:
04 Mar 2005 10:09 PST
Expires: 04 Mar 2005 14:00 PST Question ID: 484700 |
Hey i have the following query There are two tables Couples (WifeName, HusbandName) Cities(Name, City) First table contains couples and each name is unique Second table contains name of person and city where the person likes to travel to (Each person can have multiple correspondent cities) a. Find couples that like to travel to the same city (in format WifeName, HusbandName, City) b. Find couples that do not have the same city All sql people give it a shot, sorry guys only have $2.50 to spare. |
|
There is no answer at this time. |
|
Subject:
Re: SQL Query for sql junkies
From: willcodeforfood-ga on 04 Mar 2005 12:42 PST |
Your problem statements are a tad ambiguous. The wordings as I am interpreting are: a. Find all cities where both the husband and wife like to travel. You say find all couples, so it sounds like you want unique couples. It is possible, however, that a sinlge couple have more than one city in common. Then your answer format asks for city name, which sounds like you want each city, even if the couple repeats for multiple cities. b. Find all couples such that the wife and husband do not have any cities in common. SQL a. select distinct WifeName, HusbandName, hc.City from Couples c join Cities hc on (c.HusbandName = hc.Name) join Cities wc on (c.WifeName = wc.Name) where hc.City = wc.City b. select WifeName, HusbandName from Couples where WifeName not in ( select distinct WifeName from Couples c join Cities hc on (c.HusbandName = hc.Name) join Cities wc on (c.WifeName = wc.Name) where hc.City = wc.City ) |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |