On Mon, 2009-08-17 at 15:05 -0700, Leo Freitag wrote: > David Bicking-2 wrote: > > > > As written, you were selecting any record with the correct date > > regardless of Ensemble or Steuck. > > > > David
> The following seem to work: > > SELECT * FROM tblZO_Haupt AS hpt > WHERE > hpt.zo_tblEnsemble = .... > AND hpt.zo_tblStueck = ... > AND hpt.datum = ( > SELECT MAX(hpt_sub.datum) > FROM tblZO_Haupt AS hpt_sub > WHERE hpt_sub.zo_tblSaenger = hpt.zo_tblSaenger > AND hpt_sub.zo_tblEnsemble = hpt.zo_tblEnsemble > AND hpt_sub.zo_tblStueck = hpt.zo_tblStueck > AND hpt_sub.datum <= '2009-08-03 00:00:00'); > > But I didn't really get the deeper meaning of the three conditions in the > subquery: hpt_sub.xyz = hpt.xyz? > > Leo > > That will work because it forces the subquery and main query to look at the same values for tblSaenger, tblEnsemble and tblStueck. David _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users