Query inside query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Query inside query?

Post 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.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

joins

Post by djot »

-
Hi,

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

djot
-
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Post 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?
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

query example

Post 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
-
Post Reply