---
title: "UNION"
type: "forum-thread"
url: "https://www.webforum.nu/amne/databaser-sql/68614-union"
topic: "Databaser & SQL"
topic_url: "https://www.webforum.nu/amne/databaser-sql"
author: "Eclipse"
published: "2003-02-18T10:41:47.000Z"
updated: "2003-02-18T15:23:17.000Z"
replies: 1
views: 137
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/68614-union"
---

# UNION

## #1 — Eclipse, 2003-02-18T10:41Z

Detta är en follow-up från [denna tråden](http://www.webforum.nu/showthread.php?s=&postid=432339#post432339).

Jag har modifierat koden till:

```
' ## SELECT MAILINGLISTS
SQL = " SELECT m.intID, m.strName, 'TRUE' as Subscriber" _
& " FROM mailinglist m, users u " _
& " WHERE EXISTS " _ 
& " (SELECT intID FROM subscribers s WHERE s.intUserID = u.intID AND s.intMailinglistID = m.intID AND s.intUserID = " & request("ID") & ") " _
& " UNION " _
& " SELECT m.intID, m.strName, 'FALSE' " _
& " FROM mailinglist m, users u " _
& " WHERE NOT EXISTS " _
& " (SELECT intID FROM subscribers s WHERE s.intUserID = u.intID AND s.intMailinglistID = m.intID AND s.intUserID = " & request("ID") &");"
set mySQL = Conn.Execute(SQL)
listMailinglist = mySQL.GetRows()
```

[Här ser ni resultatet.](http://www.olailindgren.se/jakob/kod.gif)
Det är följdaktligen inte superläckert.  jag vill ju inte att samma post ska finnas med två gånger! Vad göra??

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

## #2 — Eclipse, 2003-02-18T15:23Z

This is the way

```
' ## SELECT MAILINGLISTS
SQL = " SELECT m.intID, m.strName, 'TRUE' as Subscriber" _
& " FROM mailinglist m, [b]users u[/b] " _
& " WHERE EXISTS " _ 
& " (SELECT intID FROM subscribers s WHERE s.intUserID = u.intID AND s.intMailinglistID = m.intID AND s.intUserID = " & request("ID") & ") " _
& " UNION " _
& " SELECT m.intID, m.strName, 'FALSE' " _
& " FROM mailinglist m, [b]users u[/b] " _
& " WHERE NOT EXISTS " _
& " (SELECT intID FROM subscribers s WHERE s.intUserID = u.intID AND s.intMailinglistID = m.intID AND s.intUserID = " & request("ID") &");"
set mySQL = Conn.Execute(SQL)
listMailinglist = mySQL.GetRows()
```

```
' ## SELECT MAILINGLISTS
SQL = " SELECT m.intID, m.strName, 'TRUE' as Subscriber" _
& " FROM mailinglist m " _
& " WHERE EXISTS " _ 
& " (SELECT intID FROM subscribers s WHERE s.intUserID = u.intID AND s.intMailinglistID = m.intID AND s.intUserID = " & request("ID") & ") " _
& " UNION " _
& " SELECT m.intID, m.strName, 'FALSE' " _
& " FROM mailinglist m " _
& " WHERE NOT EXISTS " _
& " (SELECT intID FROM subscribers s WHERE s.intUserID = u.intID AND s.intMailinglistID = m.intID AND s.intUserID = " & request("ID") &");"
set mySQL = Conn.Execute(SQL)
listMailinglist = mySQL.GetRows()
```

Nu svarar jag mig själv. Ta bort users u så fungerar det!

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

---

Tråden på webben: https://www.webforum.nu/amne/databaser-sql/68614-union
