SQL 2 INNER JOINS with 3 tables

Posted by Jelmer Holtes on Stack Overflow See other posts from Stack Overflow or by Jelmer Holtes
Published on 2012-06-10T13:10:11Z Indexed on 2012/06/10 16:40 UTC
Read the original article Hit count: 250

Filed under:
|
|
|
|

I've a question about a SQL query.. I'm building a prototype webshop in ASP.NET Visual Studio. Now I'm looking for a solution to view my products. I've build a database in MS Access, it consists of multiple tables.

The tables which are important for my question are:

  • Product
  • Productfoto
  • Foto

Below you'll see the relations between the tables

For me it is important to get three datatypes: Product title, price and image. The product title, and the price are in the Product table. The images are in the Foto table.

Because a product can have more than one picture, there is a N - M relation between them. So I've to split it up, I did it in the Productfoto table.

So the connection between them is:

product.artikelnummer -> productfoto.artikelnummer 
productfoto.foto_id -> foto.foto_id

Then I can read the filename (in the database: foto.bestandnaam)

I've created the first inner join, and tested it in Access, this works:

SELECT titel, prijs, foto_id
FROM Product
INNER JOIN Productfoto
ON product.artikelnummer = productfoto.artikelnummer

But I need another INNER JOIN, how could I create that? I guess something like this (this one will give me an error)

SELECT titel, prijs, bestandnaam
FROM Product 
(( INNER JOIN Productfoto ON product.artikelnummer = productfoto.artikkelnummer )
INNER JOIN foto ON productfoto.foto_id = foto.foto_id)

Can anyone help me?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET