hi,
I'm doing a database for renting apartments, and initially my simple database has a table of apartments, with simple criteria. For instance
Name, address, bedrooms, floor...
I'm now trying to make it more generic so it can be re-used by more people, and allow the users to add new criteria (for instance Bedrooms and Floor are pretty standard, but someone might also want Number of Beds, or town district etc).
So now I have;
Apartments: Name, address
Criteria: CriteriaName, apartment, value
it's many Criteria to one Apartment, so we might have
Apartment( 'RoseApt', '23 Abbey Lane')
and
Criteria('Bedrooms', 'RoseApt', '5')
Criteria('Floor', 'RoseApt', '2') etc.
This seemed a good idea until I tried to do a query.
In my previous simple table I could do;
Code:
select * from Apartments where Floor < 4 and Bedrooms = 2;
The closest I could get was;
Code:
SELECT * FROM Apartments inner join Criteria on
Apartments.Name=Criteria.apartment and ((CriteriaName='Floor' and
criteriavalue < 4 ) or ( CriteriaName='Bedrooms' and criteriavalue=2 ))
but unsurprisingly this isn't right as it gives a result even if one of the criteria is false (ie Bedrooms = 1 not 2).
What I want is to use 'and' instead of the 'or', but it's obvious why that doesn't work - so how to do I do this? Does it have to break down to a mulit stage process where I try each criteria in turn whittling down the group? This seems like an expensive way of doing things.
Maybe it's just a bad design?
thanks,
nik