query help please
- From: "Pedro" <Pedro@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 6 Apr 2005 01:27:03 -0700
Hi,
I wanted to add the result of a second query to each row of a first query.
Example:
I have a query like this
select field1, field2 from t1 inner join t2 on t1.field11 = t2.field11
and I wanted the final result to have a 3 column with the result of the
following query using the values from the first query on the qhere clause of
the second
select field3 from t3 inner join t4 on t3.f22 = t4.f22
where field4 = field1 (value from the 1 query) and field5 <= field2 (value
also from the same query)
How can I do this?
Can it be done on a single query?
Thanks in advance
Pedro
--
real queries:
SELECT CAST(sectionDefinition.sectionID AS int) AS IDLinha,
sectionMainDefinition.sectionName AS NomeLinha, trainDefinition.node,
sectionDefinition.km1 AS pk, trainDefinition.sequence
AS sequence, nodesDefinition.commercialName AS Nomeestacao,
(SELECT DISTINCT TOP 1 tab_CK_Trocos.IDTroco
FROM sectionDefinition INNER JOIN
tab_CK_Trocos ON
sectionDefinition.node = tab_CK_Trocos.DepInicio
WHERE (sectionDefinition.histDate IS NULL)
AND (sectionDefinition.sectionID = IDLinha) AND (sectionDefinition.km1 <=
pk)) AS IDTROCO
FROM trainDefinition INNER JOIN
sectionDefinition ON trainDefinition.sectionID =
sectionDefinition.sectionID AND trainDefinition.node = sectionDefinition.node
INNER JOIN
sectionMainDefinition ON sectionDefinition.sectionID =
sectionMainDefinition.sectionID INNER JOIN
nodesDefinition ON trainDefinition.node =
nodesDefinition.nodeID
WHERE (trainDefinition.trainNumber1 = 180) AND (trainDefinition.histDate
IS NULL) AND (sectionDefinition.histDate IS NULL) AND
(trainDefinition.endDate > GETDATE()) AND
(sectionMainDefinition.histDate IS NULL) AND (nodesDefinition.histDate IS
NULL)
ORDER BY trainDefinition.sequence
.
- Follow-Ups:
- RE: query help please
- From: Chaim
- RE: query help please
- Prev by Date: RE: data_type - is there a list of definitions
- Next by Date: Re: Display results from a DataGrid in labels
- Previous by thread: the rowset is not bookmarkable
- Next by thread: RE: query help please
- Index(es):
Relevant Pages
|