|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Im pretty new to SQL and any help would be greatly appreciated
I have three tables, a property table, facility table and propertyFacilities table. propertyFacilities table -------------- facility_id property_id facility table -------------- facility_id facility_name property_table -------------- property_id property_name etc etc A property can have quite a few facilities. In my statement i need to return the property which has all of the facilities that have been selected. How can I do this? Dave Last edited by dast : February 23rd, 2004 at 05:03 AM. |
|
#2
|
||||
|
||||
|
Code:
select P.property_id
, P.property_name
from propertyFacilities PF
inner
join property_table P
on PF.property_id = P.property_id
group
by P.property_id
, P.property_name
having count(*) =
( select count(*)
from facility )
|
|
#3
|
||||
|
||||
|
thankyou very much for your reply
![]() but whereabouts in the SQL would i pass through the id's? i have about 20 facility checkboxes on the previous page so based on the ones checked i need to find the property that matches. |
|
#4
|
||||
|
||||
|
finding the facilites matched, which may be fewer than all of them, is a slightly different query from finding properties with all facilities
Code:
select P.property_id
, P.property_name
from propertyFacilities PF
inner
join property_table P
on PF.property_id = P.property_id
where PF.facility_id
in ( 3, 7, 14, 52 ) -- list the facility ids
group
by P.property_id
, P.property_name
having count(*) = 4 -- the number listed
|
|
#5
|
||||
|
||||
|
cheers mate - just waiting for SQL enterprise manager to install, i'll let you know how i get on!!
|
|
#6
|
||||
|
||||
|
works like a dream, thanks a lot mate
|
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > querying with multiple ids |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|