Page 1 of 1

Query inside query?

Posted: Wed Jan 14, 2004 10:06 am
by Perfidus
I have two tables in a DB, let's say one of the tables talks about services given by a hotel:
Table "Services"
- Hotel reference number
- Sauna
- Massage
- Spa
- Uva
The other table talks about availability:
Table "Availability"
- Hotel reference number
- week1
- week2
- week3
I wonder if it is possible to make a query that shows the reference numbers of all hotels having Sauna and Uva and being available week3.
To change tables is not a possibility.

joins

Posted: Wed Jan 14, 2004 10:21 am
by djot
-
Hi,

it's possible to "connect" several tables with JOINS. Read about it on mysql.com or elsewhere existing tutorials.

djot
-

Posted: Wed Jan 14, 2004 10:23 am
by Perfidus
I'm thinking about the question and I guess what I have to do is 2 different querys, one for "Availability" and the other for "Services", to place results in 2 arrays and after compare arrays creating a new array that contains only the coincidences.
But, how to?

query example

Posted: Wed Jan 14, 2004 10:33 am
by djot
-
Hi,

It looks like this, only one query:
SELECT * from db1,db2 WHERE (refno_db1=refno_db2 AND sauna='1' AND uva='1' AND week='3')
but there are several ways to do it, so study tutorials about all kind of joins (left, right, outer, inner and full joins) or you won't get good results nor good performance.

djot
-