views:

44

answers:

3

Hi there,

im developing a simple access application that helps us to order the right products for a project. i have a table for each contractor containing its products. i have a table "favorite-products" that relates to products and gives additional information how and when they should be used.

normally id have a big table (containing all products) that has a contractor-column. i my favorite-products table i could then easyly relate to a product. but here i need to keep the products in separate tables. so whats the best way to connect my favorite-products table with the products in the contractor-tables?

thanks :)

+1  A: 

I would create a contractors table, a product table and then a many-to-many linked table contractors to products. Also i would create a favorite-products table in which you can also have a many-to-many contractors to products link for those cases where a product can come from more than 1 contractor

astander
i dont want do that. i get the price-lists as xls from the contrators (many contrators). one up to five times a year. the xls is then converted to access (easy) an plugged into the database. i would have to delete all the products from the big table and put the new ones back into it. id rather keep them separeted if there is a clean way...
Dill
the price lists should be handles seperately from the main list of products, they should be handled as as at date prices were for products, so that you have a table with the product id, the data as at and the price at that date
astander
Carlo, life is going to be a *lot* easier if you combine all the products from all the contractors into one table. Otherwise you will be spawning multiple forms and queries for each contractor. It'll get real ugly real soon.
Tony Toews
+1  A: 

This is not the best design.

You should UNION all contractor tables together and JOIN with the result:

SELECT  *
FROM    (
        SELECT  product
        FROM    contractor1
        UNION ALL
        SELECT  product 
        FROM    contractor2
        UNION ALL
        …
        ) c
JOIN    favorite f
ON      f.product = c.product

You better keep one single table for you products with contractor as a field.

It will be much easier to query and to manage.

Quassnoi
i think ill just write a script to update the all_products table when a new price list arrives from a contractor...thank you guys.
Dill
A: 

So, you'll have a Contractor, Product and Contractor_Product table. Something like (in psuedo-sql):

create table Contractor {
  id int primary key,
  name varchar(50) not null,
  ...
}

create table Product {
  id int primary key,
  name varchar(50) not null,
  ...
}

create table Contractor_Product {
  contractorid int references Contractor(id),
  productid int references Product(id),
  ...,
  primary key contractorid, productid
}

Now, I'm not 100% sure what you want from the "Favorites" table. It may not be a table, but rather a query. Or, maybe you want a table that similar to the Contractor_Product table? Or just another "isfavorite bool default=false" column on the Contractor_Product table?

Hope that helps!

Todd R