Ask a Question related to IBM DB2, Design and Development.
-
blake #1
sub select vs. join
Can anyone help convert the following sub-select into a join of some
kind that will return the results described below?
SELECT A.RST
FROM A
WHERE A.PROC = 'AAAA'
AND A.RST NOT IN
(
SELECT B.RST
FROM B
WHERE A. PROC = B.PROC
AND B.USERID = 'PGM'
)
A.RST can be 'O', 'P', 'Q', or 'R'.
B.RST is 'Q' or 'R'.
Valid result is 'O' and 'P'. PROC and RST are the only 'joinable'
columns in A and B tables
Thanks
blake Guest
-
Select, Join & field values - 2 tables
I had originally posted this in alt.comp.databases.mysql with no replies (I thought I had posted it here, my bad). Hopefully one of you bright... -
Sub-Select vs. Join
Hi All, I have two tables. One table holds a list of states names. The other table holds the statesID the user slected along with there... -
Union or Join or Nested Select - Can't Remember
Its been along time since I have had to write tsql from the hip so any help would be greatly valued. I have a table that contains Country, State,... -
trying to update a table after making a join select query on two tables
here is my problem distilled down I need to be able to change the title of a book associated with an author there are 2 tables "author" and "books"... -
SELECT from multiple tables (not join though)
Hi all, I have another question, I hope it isn't too basic. ^.^ I want to do a select from multiple tables but not join them. What I am trying... -
Ian D. Bjorhovde #2
Re: sub select vs. join
On 30 Jul 2003, blake wrote:
> Can anyone help convert the following sub-select into a join of some
> kind that will return the results described below?
>
> SELECT A.RST
> FROM A
> WHERE A.PROC = 'AAAA'
> AND A.RST NOT IN
> (
> SELECT B.RST
> FROM B
> WHERE A. PROC = B.PROC
> AND B.USERID = 'PGM'
> )
>
> A.RST can be 'O', 'P', 'Q', or 'R'.
> B.RST is 'Q' or 'R'.
> Valid result is 'O' and 'P'. PROC and RST are the only 'joinable'
> columns in A and B tables
If you have to join using the column RST then you have no choice
but to do a correlated subselect.
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
[url]http://www.newsfeeds.com[/url] - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
Ian D. Bjorhovde Guest
-
Tokunaga T. #3
Re: sub select vs. join
[email]blake_samples@labcorp.com[/email] (blake) wrote in message:
Example1:> Can anyone help convert the following sub-select into a join of some
> kind that will return the results described below?
>
> SELECT A.RST
> FROM A
> WHERE A.PROC = 'AAAA'
> AND A.RST NOT IN
> (
> SELECT B.RST
> FROM B
> WHERE A. PROC = B.PROC
> AND B.USERID = 'PGM'
> )
>
> A.RST can be 'O', 'P', 'Q', or 'R'.
> B.RST is 'Q' or 'R'.
> Valid result is 'O' and 'P'. PROC and RST are the only 'joinable'
> columns in A and B tables
>
I could't understand why you want to use join.
Anyway here is an example, but only for my pleasure. This query must
have performance problem, and not so straightforward.
SELECT A.RST
FROM A
LEFT OUTER JOIN
B
ON A.PROC = B.PROC
AND A.RST = B.RST
AND B.USERID = 'PGM'
WHERE A.PROC = 'AAAA'
AND B.RST IS NULL
;
Example2:
You can use EXISTS predicate instead of IN predicate.
SELECT A.RST
FROM A
WHERE A.PROC = 'AAAA'
AND NOT EXISTS
(
SELECT *
FROM B
WHERE A.PROC = B.PROC
AND A.RST = B.RST
AND B.USERID = 'PGM'
)
;
Tokunaga T. Guest



Reply With Quote

