Hello everyone
I hope this is the right list for my question if not please let me know.

First I've got to say that I'm not an experienced "query-builder" so maybe
the answer to my problem is very easy. But I have no idea how I could solve
this problem and all my research (Internet and Forums) did not help me :(

I am working on a hotel database.
Every hotel has some general data like name, address,... and can provide one
or many services. And a service can be for 0 or many hotels. So we have a
many to many link.
A hotel can also provide one or many spare time activity's and this
activity's can be for 0 or many hotels. So another many to many link.

I've created a link-table for activity's and services in which i link the
hotels to the category by ID. 

So here are my tables:
- stammdaten (id_PK, name, description, address, location...)
- services (id_PK, servicesname)
- relation_services (hotelid, serviceid)
- sparetime (id_PK, sparetimename)
- relation_sparetime (hotelid, sparetimeid)

I need to create a search Query to find all the hotels which have specific
services and sparetime activities. 
For example:
Search for hotels where location is "Bern" and the hotel has sparetime
activity 2 and 5 AND services 5 and 3 and 7
So only hotels which match all the expressions should appear as results.

I've tried it with the following Query but this doesn't work as it should.

****************************************************************************
*
SELECT  * 
FROM stammdaten
INNER JOIN relation_services ON stammdaten.id_PK = relation_services.hotelid
INNER JOIN relation_sparetime ON stammdaten.id_PK =
relation_sparetime.hotelid
WHERE 
stammdaten.location LIKE 'Bern' AND
relation_services.serviceid IN (5, 3, 7 ) AND
relation_sparetime.sparetimeid IN (2, 5) AND
GROUP  BY stammdaten.name
ORDER  BY stammdaten.name
****************************************************************************
*

I'm trying to get this working for more than a week now but couldn't find a
solution.

Maybe this isn't possible in a single query ?
But I have no idea how to get this working in another way.

Hope somebody here can help me with this.

O.Salzgeber




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to