August 20, 2008
For ColdFusion hosting try HostMySite.com. |
Home /
Groups /
ColdFusion Talk (CF-Talk)
What relationship am I missing in this query ?
I think you need to move your second query out of the select statement and into the join section of the query.Chad Gray 05/21/08 01:11 P Thanks for the tips, Chad!Rick Faircloth 05/21/08 09:19 P 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 ----- 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 -----
|
Mailing Lists
|
Latest Fusion Authority Articles
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||