Re: Exists
From: Michael C# (xyz_at_abcdef.com)
Date: 02/07/05
- Next message: Dan Guzman: "Re: Exists"
- Previous message: Alan: "Re: Exists"
- In reply to: Alan: "Re: Exists"
- Next in thread: Dan Guzman: "Re: Exists"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 6 Feb 2005 23:04:04 -0500
I see what you're trying to say. You need to relate the queries yourself in
the WHERE clause of the subquery, something like this:
SELECT *
FROM table1
WHERE EXISTS (SELECT * FROM table2 WHERE table2.field1 = table1.field1)
The correlation you're looking for is between a column in the table1 outer
query and a column in the table2 subquery. You introduce that via the WHERE
clause of the subquery. I can't imagine too many situations where you would
add an EXISTS predicate with a subquery that didn't relate to your outer
query, at least none that couldn't be better modeled using a simple JOIN in
the outer query.
Thanks,
Michael C#
"Alan" <NOSPAMalan_pltse@yahoo.com.au> wrote in message
news:eoE9neMDFHA.464@TK2MSFTNGP15.phx.gbl...
> Actually, I know the EXISTS return FALSE when now records in subquery and
> TRUE when there is records returned.
> The thing I in the dark is using this EXISTS predicate, how the subquery
> relate to the outer query ?
>
> SELECT *
> FROM table1
> WHERE EXISTS ( SELECT * FROM table2 WHERE table2.field1 = blah)
>
> The subquery has no relationship with the outer table1.
>
>> Consequently, the output is the same as long as at least one row
>> satisfies
>> the criteria. The EXISTS condition is false when no rows match.
>
>
- Next message: Dan Guzman: "Re: Exists"
- Previous message: Alan: "Re: Exists"
- In reply to: Alan: "Re: Exists"
- Next in thread: Dan Guzman: "Re: Exists"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|