freetds AT lists.ibiblio.org
Subject: FreeTDS Development Group
List archive
- From: "Lowden, James K" <LowdenJK AT bernstein.com>
- To: 'FreeTDS Development Group' <freetds AT lists.ibiblio.org>
- Subject: RE: [freetds] SQL Query troubles
- Date: Thu, 8 Jan 2004 14:08:08 -0500
> From: Steven Orton [mailto:sorton9999 AT usa.net]
> Sent: January 8, 2004 1:57 PM
>
> I seem to be having problems with the following query:
>
> SELECT * FROM table1 WHERE Target_ID=(SELECT DISTINCT
> Target_ID FROM table2
> WHERE PlatformTypeID=62 AND db_ctx_id=3)
It's not a good idea to rely on a subquery returning only one row to a point
evaluation. How do you expect the server to cope if it returns two
(distinct) Target_IDs?
I would do:
SELECT * FROM table1
WHERE Target_ID in (
SELECT DISTINCT Target_ID
FROM table2
WHERE PlatformTypeID=62
AND db_ctx_id=3
)
or, ensure the subquery really really returns only one row, viz:
SELECT * FROM table1
WHERE Target_ID = (
SELECT min(Target_ID)
FROM table2
WHERE PlatformTypeID=62
AND db_ctx_id=3
)
The right choice depends on the situation.
HTH. :-)
--jkl
-----------------------------------------
The information contained in this transmission may contain privileged and
confidential information and is intended only for the use of the person(s)
named above. If you are not the intended recipient, or an employee or agent
responsible for delivering this message to the intended recipient, any
review, dissemination, distribution or duplication of this communication is
strictly prohibited. If you are not the intended recipient, please contact
the sender immediately by reply e-mail and destroy all copies of the original
message. Please note that we do not accept account orders and/or instructions
by e-mail, and therefore will not be responsible for carrying out such orders
and/or instructions.
-
[freetds] SQL Query troubles,
Steven Orton, 01/08/2004
- <Possible follow-up(s)>
-
RE: [freetds] SQL Query troubles,
Lowden, James K, 01/08/2004
- RE: [freetds] SQL Query troubles, Michael Peppler, 01/08/2004
- RE: [freetds] SQL Query troubles, brian, 01/08/2004
Archive powered by MHonArc 2.6.24.