BrighteyesDesign
asked on
Show featured products
For a real estate site.....
I have a table named 'properties' which hold all of the properties details and another called 'featured' which states which properties are features.
The 'featured' table has the columns id (primary) and property_id which relates to the id on the properties table.
I basically need to know the query to display the featured properties which, at the moment would be properties with the id's 15,16 & 17 (see attachment)
Screen-shot-2012-03-14-at-10.01..png
Screen-shot-2012-03-14-at-10.01..png
I have a table named 'properties' which hold all of the properties details and another called 'featured' which states which properties are features.
The 'featured' table has the columns id (primary) and property_id which relates to the id on the properties table.
I basically need to know the query to display the featured properties which, at the moment would be properties with the id's 15,16 & 17 (see attachment)
Screen-shot-2012-03-14-at-10.01..png
Screen-shot-2012-03-14-at-10.01..png
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SELECT p.* FROM properties p ,featured f
WHERE p.property_id= f.property_id;
WHERE p.property_id= f.property_id;
SELECT p.* FROM featured
LEFT JOIN properties as p
ON propertyID = property_id
Should give you what you are looking for. HTH
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
That's what I meant by this I wrote earlier >>>"You will have to write condition after first where condition based on what you're choosing featured properties to be displyed?"
Btw, joins will help you out but a boolean column will ease out your task!
Btw, joins will help you out but a boolean column will ease out your task!
ASKER
Just one thing...15,16 & 17 are just the id's of what should show. They shouldn't be part of the query.
The query needs to be...Display properties from the 'properties' table if their ID is in the property_id column of the 'featured' table
Hope this makes sense!