Discussion Locked

SQL Server7 the opposite of union?

0 helpful
9 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have two tables. I want to query for all records in one table that are not in the other. I know in paradox it is count = o but what is it in sql server 7? Is it the opposite of union and if so what do i use to get the opposite of union?

9 replies

by sparent

In Oracle, I would do the following:

SELECT col1, col2, ..., coln
FROM table1
MINUS
SELECT col1, col2, ..., coln
FROM table1

Hopefully, SQL Server has the MINUS set operator, though it may be called differently!

And, no, MINUS is not the opposite of UNION!

by raffi_

I think you are looking for a NOT IN sub-query:

USE pubs
SELECT pub_name
FROM publishers
WHERE pub_id NOT IN
(SELECT pub_id
FROM titles
WHERE type = 'business')

Should work in both Oracle and MS SQL

Regards
Raffi_

by jay eckles

Mathematically speaking, the "opposite" of a union would be an intersection. I suggest you investigate the INTERSECT reserved word in SQL Server documentation. Unfortunately, I don't have the documentation available to me at the moment.

by rsv

HI,
Try this....

SELECT * FROM authors WHERE NOT EXISTS
(SELECT * FROM publishers WHERE
authors.city = publishers.city)

Hope this helps you.
Good Luck...:)

This discussion is closed to new replies.