Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

repeated field query question

Status
Not open for further replies.

shopwise

Technical User
Sep 22, 2008
52
US
my database contains a listing of products. some products are members of a productfamily as they are the same product except for a different size etc and some are not productfamily members.

the "products" table indicates which products are associated with which productfamily, if any, with the use of the productid (primary key), productfamily fields

with a many-to-many-relationship table named "products_images", I have specified which productid or productfamily every image_url should be associated with by using these fields:
images.image_url, products.productid, products.productfamily. so for some images i have matched up a productid and for some a productfamily, the latter, for when i would like a single image to repeat by each member of a productfamily.

what i would like to do is create a query which would repeat an image_url value (pulled from the products_images table) for every productid value (pulled from the products table) that is a member of the productfamily that is specified in the products_images table. i suppose this would be accomplished by joining the productfamily field of both tables.

how is such a query created
 
It sounds like you have something like this:

[tt]
Products
ProductID
ProductFamilyCode

Product_Images
ImageID
URL
ProductFamilyCode[/tt]

you would then just JOIN and get the results you want:
Code:
SELECT * FROM 
Products P
INNER JOIN Product_Images I ON P.ProductFamilyCode = I.ProductFamilyCode

you may want to read Understanding SQL Joins

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top