---
title: "Destinct Join-sats"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/128692-destinct-join-sats"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "jockooono"
published: "2005-05-22T17:32:24.000Z"
updated: "2005-05-23T09:55:02.000Z"
replies: 5
views: 385
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/databaser-sql/128692-destinct-join-sats"
---

# Destinct Join-sats

## #1 — jockooono, 2005-05-22T17:32Z

SQL-saten nedan använder jag för att för att joina tabellen produkter men tabellen produktbilder. Hur gör jag om en produkt har flera bilder men jag vill bara att SQL-satsen ska returnera en rad. Har försökt med SELECT DISTINCT men får det inte att fungera.

```
SELECT Product.ProductID, Product.Productname, Product.Producttext,
Productimage.ImageID, Productimage.ProductID, Productimage.Imagename, Productimage.Description 
FROM Product LEFT JOIN Productimage ON Product.ProductID = Productimage.ProductID
```

Permalänk: https://www.webforum.nu/p/128692

## #2 — LarsG, 2005-05-23T07:24Z

Vad skulle den raden innehålla då? Om du vill ha alla bilder så är det en presentationssak som man företrädelsevis hanterar i sin applikation och inte med SQL.

Permalänk: https://www.webforum.nu/p/1615598

## #3 — jockooono, 2005-05-23T08:09Z

Jag vill att alla produkter skrivs ut på en sida och där ska det bara stå om produkten har en bild eller inte. Typ:

\<%
Response.Write(RS("Productname"))

If Len(RS("Imagename")) \> 0 Then 
 Response.Write("Bild finns")
Else
 Response.Write("Bild finns inte")
End if 
%\>

Permalänk: https://www.webforum.nu/p/1615618

## #4 — LarsG, 2005-05-23T08:13Z

```
SELECT 
   ProductID,
   Productname, 
   Producttext,
(select max(imagename)
    from productimage
  where  Productimage.ProductID = product.productid) as imagename
FROM Product
```

Permalänk: https://www.webforum.nu/p/1615624

## #5 — jockooono, 2005-05-23T09:25Z

Prefect! Tackar

Permalänk: https://www.webforum.nu/p/1615666

## #6 — @nders, 2005-05-23T09:55Z

<http://www.webforum.nu/misc.php?s=&action=faq&page=2#status>

Permalänk: https://www.webforum.nu/p/1615689

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/128692-destinct-join-sats
