One way to get at this in SQL is to use nested queries.
For example, to find out who likes Vegas, New York, and Boston, you could
use the following query:
SELECT Name
FROM tblFavCities
WHERE City = "Vegas" AND Name IN
(SELECT Name FROM tblFavCities WHERE City = "NY" and Name IN
(SELECT Name FROM tblFavCities WHERE City = "Boston"))
To break it down, the last query is evaluated first and it returns the
set of people with Boston as a favorite city. This would be John, Eddie
and Burt.
That list of people becomes a condition for the next query up, which then
returns the people who both match the list and have NY as a favorite
city. These are John and Eddie.
So John and Eddie are the ones passed on to the top query which returns
which of them is both on the list and has Vegas in their city list.
Finally, the query returns John.
To add another city to the list you would simply add an IN to the last
WHERE clause and slide in another subquery. Also, you can place
parameters in the slots for cities if you always wanted to search for a
set number of cities. Otherwise you could build this statement in code
fairly easily.
Hope that helps,
Carlos
eddiesmit@freeler.nl (Eddie Smit) wrote in
news:9d7d5799.0310080557.1fac903e@posting.google.c om:
[color=blue]
> field- field-
> surname town
> ---- ----
>
> john NY
> john Vegas
> john Boston
> eddie Boston
> eddie New Orleans
> eddie NY
> burt Miami
> burt Boston
> hank NY
>
> Hi all,
> In the example you see the content of a table of persons with their
> favorit town (the table consists of two fields, name and town)
> How can a make a query that returns the persons who like certain
> towns?
>
> for example: what persons like Boston and NY?
> the answer is John and Eddie, BUT how do I do this in a query?
> In real the table is much bigger and do I need to query with different
> towns another example: who likes NY, Boston and Vegas, answer: john
> (Sorry, maybe a simple question)
>
> Best regards and thanks in advance,
>
> Eddie Smit.
> Holland[/color]