House of Fusion
Home of the ColdFusion Community
Hostmysite VPS Hosting

Search cf-talk

August 20, 2008

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
           1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31             

Subscribe Now
Fusion Authority Quarterly Update - ColdFusion 8 Special Edition

For ColdFusion hosting try HostMySite.com.
Search over 2,500 ColdFusion resources here  >>>      
Home /  Groups /  ColdFusion Talk (CF-Talk)

What relationship am I missing in this query ?

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Chad Gray
05/21/2008 01:11 PM

I think you need to move your second query out of the select statement and into the join section of the query.   This chunk of SQL goes and gets the most recent ElementStatusHistoryID by using a GROUP BY and uses it to join in the table at that one row that it finds with the GROUP BY. Hope it helps. SELECT c.CatalogID, c.CatalogName, c.currentStatus, ct.*, e.*, es.ElementStatus, es.ElementStatusDate, es.UserName FROM Catalogs as c LEFT JOIN Elements as e ON c.CatalogID = e.CatalogID JOIN CatalogTypes as ct ON c.CatalogTypeID = ct.CatalogTypeID LEFT JOIN (   SELECT MAX(ElementStatusHistoryID) as MaxESHID, ElementID   FROM ElementStatusHistory   GROUP BY ElementID ) as maxESH ON (e.ElementID = maxESH.ElementID) LEFT JOIN (   SELECT ElementStatusHistoryID, ElementStatus, ElementStatusDate, UserName   FROM ElementStatusHistory ) as es ON (es.ElementStatusHistoryID = maxESH.MaxESHID) WHERE c.CatalogID = #val(URL.CatalogID)# ----- Excess quoted text cut - see Original Post for more -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rick Faircloth
05/21/2008 09:19 PM

Thanks for the tips, Chad! Rick > I think you need to move your second query out of the select statement and into the join section of the > query. > > This chunk of SQL goes and gets the most recent ElementStatusHistoryID by using a GROUP BY and uses it > to join in the table at that one row that it finds with the GROUP BY. > > Hope it helps. > > SELECT c.CatalogID, c.CatalogName, c.currentStatus, ct.*, e.*, es.ElementStatus, es.ElementStatusDate, ----- Excess quoted text cut - see Original Post for more -----


<< Previous Thread Today's Threads Next Thread >>

Mailing Lists