On 6/26/2012 4:02 PM, Pavel Ivanov wrote:
On Tue, Jun 26, 2012 at 3:02 PM, Igor Tandetnik <itandet...@mvps.org> wrote:
On 6/26/2012 1:19 PM, Peter Haworth wrote:

I still have the issue that, in order to be selected,  the rows in the
groups containing two entries must have a different value in a specific
column.


I'm not quite sure I understand the condition, but perhaps you are looking
for something like this:


SELECT * from TableA WHERE z in (
  SELECT z FROM TableA GROUP BY z
  HAVING count(*)=2 and min(otherColumn) != max(otherColumn)
);

Maybe this can be simplified?


SELECT * from TableA WHERE z in (
  SELECT z FROM TableA GROUP BY z
  HAVING count(distinct otherColumn)=2
);

The two requests are not equivalent. Yours would return groups containing two *or more* rows, as long as there are only two distinct values in otherColumn. But the OP specifically asked for two-row groups only.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to