Drie tabellen

Producten-kleurcombinaties: Tabel producten (id, name..), tabel kleurcombinaties (id, prd_id, kleur).
Deze beantwoordt niet aan de typische hiërarchie van bv factuurhoofd-factuurlijn, employee-employee-registrations, enz.

Omgevormd tot drie tabellen:
product (id, name, ..)
color (id, color, ..)
productcolor (prd_id, klr_id, meta ..)

Hoe de juiste SQL syntax vinden om de combinatie op te vragen?

SELECT * 
FROM color, product, productcolor AS pc 
WHERE color.id = pc.color_id AND pc.prd_id = product.id

MySQL gebruikt standaard de inner join.

ANSI syntax moet meer inzicht geven, uit een ander voorbeeld de vorm:

SELECT s.name as Student, c.name as Course 
FROM student s
    INNER JOIN bridge b ON s.id = b.sid
    INNER JOIN course c ON b.cid  = c.id 
ORDER BY s.name 

Wordt dan:

SELECT * 
FROM color
  INNER JOIN productcolor pc ON color.id=pc.color_id
  INNER JOIN product ON pc.prd_id = product.id
ORDER BY color.color
This entry was posted in Databank. Bookmark the permalink.