We help IT Professionals succeed at work.

Show featured products

BrighteyesDesign
on
Medium Priority
429 Views
Last Modified: 2012-03-15
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
Comment
Watch Question

theGhost_k8Database Consultant
CERTIFIED EXPERT
Commented:
select p.* from properties p, featured f where p.propertyid=f.property_id and f.property_id in (15,16,17);

Check if this works for you! You will have to write condition after first where condition based on what you're choosing featured properties to be displyed?

Author

Commented:
Hi, thanks for that

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!
SanthanaTechnical Lead

Commented:
SELECT  p.*  FROM properties p ,featured f
WHERE p.property_id= f.property_id;
SELECT p.* FROM featured
   LEFT JOIN  properties as p
      ON propertyID = property_id

Open in new window

Should give you what you are looking for. HTH
Most Valuable Expert 2011
Author of the Year 2014
Commented:
I think I might let the "featured" fact be a column in the properties table.  It's not relational to anything else as far as I can see.  Then it would be SELECT things FROM table WHERE featured = 1 (or something to that effect).
theGhost_k8Database Consultant
CERTIFIED EXPERT

Commented:
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!

Explore More ContentExplore courses, solutions, and other research materials related to this topic.