Gary, You can only have one field returned in the where "sub select" (i.e the right hand side) because you are comparing it to one field A.Cycle in the right hand side.
Before giving a solution I need to get a feel for the data and EXACTLY what you want to return. Do you have a unique PK that you can first extract in the sub query as a single unique entity for each record and then and then extract the full record for each entity in the main select. That is the most efficient way to do it. Eg, assuming the Unique key is called PK Select * ; >From FileA ; Where FileA.PK in (select all FileB.PK from FileA FileB where ........) ; Group by <.....> Dave Crozier -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Garry Bettle Sent: 18 November 2009 15:23 To: [email protected] Subject: VFP SQL subquery error Hi Everyone, Hope this email finds you all well - roll on the weekend. I have a query that isn't working at the moment - it returns, "SQL: Subquery is invalid" The subquery works fine on it's own: SELECT TOP 1 b.Cycle, b.DTime FROM LPMHistory b GROUP BY b.Cycle, b.DTime WHERE b.DTime > CTOT( GETWORDNUM( JUSTSTEM( JUSTPATH( CURDIR())), 1) + [T] + STUFF( GETWORDNUM( JUSTSTEM( JUSTPATH( CURDIR())), 2), 3, 0, [:])) - 180 ORDER BY b.Cycle, b.DTime It returns a cursor: Cycle Dtime 71 25/09/2009 22:37:01 Now, > 1 record exist in LPMHistory with Cycle = 71 that I thought I could fetch by wrapping the above SQL as so: SELECT * FROM LPMHistory a WHERE a.Cycle in ( SELECT TOP 1 b.Cycle, b.DTime FROM LPMHistory b GROUP BY b.Cycle, b.DTime WHERE b.DTime > CTOT( GETWORDNUM( JUSTSTEM( JUSTPATH( CURDIR())), 1) + [T] + STUFF( GETWORDNUM( JUSTSTEM( JUSTPATH( CURDIR())), 2), 3, 0, [:])) - 180 ORDER BY b.Cycle, b.DTime) but this doesn't work. Any ideas? Many thanks! Cheers, Garry --- StripMime Report -- processed MIME parts --- multipart/alternative text/plain (text body -- kept) text/html --- [excessive quoting removed by server] _______________________________________________ Post Messages to: [email protected] Subscription Maintenance: http://leafe.com/mailman/listinfo/profox OT-free version of this list: http://leafe.com/mailman/listinfo/profoxtech Searchable Archive: http://leafe.com/archives/search/profox This message: http://leafe.com/archives/byMID/profox/ea6f719d8cd0408390d63db67940f...@develop ** All postings, unless explicitly stated otherwise, are the opinions of the author, and do not constitute legal or medical advice. This statement is added to the messages for those lawyers who are too stupid to see the obvious.

