Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / DB Engine / SQL Server / June 2008

Tip: Looking for answers? Try searching our database.

relate an aggregate subquery to the first query

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Janis Rough - 26 Jun 2008 18:26 GMT
The first SELECT works but I want to filter it with a subquery.  NOw
instead  I have  a VIEW but it is really slow.  I want to try  a
subquery but I don't know how to relate the two queries. The 2nd query
I want as a subquery not a VIEW.   The relationship would be [car_mark
AND car_number] but I don't know if I need a HAVING or an IN or
another join since it is an aggregate in the 2nd query??  Or do I need
to start all over?
tia,

SELECT c.l_e ,  c.car_mark , c.car_number ,  c.location_city ,
c.location_state ,
c.sighting_date ,  e.classification ,  c.railroad ,  s.city as
origin_city ,
s.state as origin_state ,  c.destination_city , c.destination_state ,
t.eta
FROM INTERNAL_REMARK r, INTERNAL_CAR_LEASE cl,
INTERNAL_CODES e, INTERNAL_CLM c

LEFT JOIN (
INTERNAL_TRIPS t, INTERNAL_SPLC s)
ON ( c.trip_id = t.trip_id
AND t.origin_splc_id = s.splc_id )
WHERE cl.lease_id = "74"
 AND cl.remark_id = r.remark_id
 AND r.car_mark = c.car_mark

------
(select INTERNAL_CLM.car_mark AS car_mark,
INTERNAL_CLM.car_number AS car_number,
max(INTERNAL_CLM.sighting_date)
AS sighting_date  from INTERNAL_CLM
group by INTERNAL_CLM.car_mark,INTERNAL_CLM.car_number
John Bell - 29 Jun 2008 18:22 GMT
> The first SELECT works but I want to filter it with a subquery.  NOw
> instead  I have  a VIEW but it is really slow.  I want to try  a
[quoted text clipped - 28 lines]
> AS sighting_date  from INTERNAL_CLM
> group by INTERNAL_CLM.car_mark,INTERNAL_CLM.car_number

See my reply to your other post http://tinyurl.com/6kgv5e

John
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.