---
title: "Temporary table"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/84332-temporary-table"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "cyprys"
published: "2003-08-16T07:22:49.000Z"
updated: "2003-08-16T07:48:01.000Z"
replies: 1
views: 175
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/84332-temporary-table"
---

# Temporary table

## #1 — cyprys, 2003-08-16T07:22Z

Då webbhotellet inte hade mySQL 4.1 blev jag tvungen att hantera temporära tabeller. 

```
' Skapar temporära tabeller innhållande maxbudet för varje auktionsobjekt '
        RunNonQuery("DROP TABLE IF EXISTS tmp3")
        RunNonQuery("CREATE TABLE tmp3 (maxbid int(11), aoid int(11));")

        ' Här lägger vi in värderna
        RunNonQuery("INSERT INTO tmp3 SELECT MAX(t1.bid), t1.auctionobjectid " & _
        "FROM bidding t1, auctionobjects t2 WHERE t1.auctionobjectid = t2.id AND t2.auctionid = " & auctionID & " GROUP BY 2;")
```

Tabellerna som används är auctionobjects samt bidding.
I den temporära tabellen vill jag lägga in samtliga id ur tabellen auctionobjects (där auctionid = specifikt värde).

**Bidding**
id \| auctionobjectid \| bid  

**auctionobject**
id \| auctionid

Det fungerar nu men endast de auctionobjectid som har ett bud kopplat till sig läggs in i den temporära tabellen.
Jag vill ha in alla id som följer auctionid = specifikt värde.

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

## #2 — cyprys, 2003-08-16T07:48Z

Efter lite test och knåp ur dokumentationen på mysql.com så verkar det fungera just nu i alla fall med denna kod.

```
RunNonQuery("INSERT INTO tmp3 SELECT IF(COUNT(t2.bid) = 0, 0, t2.bid), t1.id " & _
        "FROM auctionobjects t1 LEFT JOIN bidding t2 ON t1.id = t2.auctionobjectid WHERE t1.auctionid = " & auctionID & " GROUP BY 2;")
```

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

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/84332-temporary-table
