I guess you need something like SELECT * from TableA WHERE z in ( SELECT z FROM TableA GROUP BY z HAVING count(*)=2 );
Pavel On Fri, Jun 22, 2012 at 6:43 PM, Peter Haworth <p...@lcsql.com> wrote: > I have a situation where I need to select entries based on the count of the > number of entries in a GROUP = 2, and also that the value of a specific > column must be different for each row in the group. I then need to select > all the individual rows from the qualifying groups. > > Getting the groups with count=2 is pretty straightforward: > > SELECT * FROM TableA GROUP BY z HAVING count(*)=2; > > Is there a format that will allow me to have the same SELECT statement > return the individual rows from each qualifying group that have a different > value in a specific column or is this something I should do in my > application logic? The value of 'z' in the above example could be used to > select the individual rows and there are other columns in the table that > could be used in a JOIN statement to link the table to itself. > > Thanks, > > Pete > lcSQL Software <http://www.lcsql.com> > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users