From: Jason Trebilcock Date: December 13 2009 7:16pm Subject: RE: Query help List-Archive: http://lists.mysql.com/mysql/219701 Message-Id: <4b253d71.5544f10a.56a2.3589@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Depending on whether you just need to count or the transaction numbers, = one of the following three should get you where you want/need to be: To identify the count for comp_id =3D 675: select count(distinct trans_no) from trans where comp_id =3D 675 and = result =3D 'o'; To identify the transactions: select distinct trans_no from trans where comp_id =3D 675 and result =3D = 'o'; To identify the transactions and the individual counts: select trans_no, count(*) from trans where comp_id =3D 675 and result = =3D 'o' group by trans_no; > -----Original Message----- > From: Richard Reina [mailto:richard@stripped] > Sent: Sunday, December 13, 2009 12:37 PM > To: mysql@stripped > Cc: richard@stripped > Subject: Query help >=20 > I was wondering if someone could lend a hand with the following query. > I have table. >=20 > SEARCHES > |ID |trans_no|comp_id|result > 13 | 455 | 675 | o > 15 | 302 | 675 | o > 16 | 455 | 675 | o > 12 | 225 | 629 | y >=20 > SELECT count(*) FROM SEARCHES WHERE comp_id=3D675 AND result=3D'o' = GROUP BY > trans_no; >=20 > gives me a count of 3. >=20 > However, what I need is a count for how many different (unique) > transactions company number 675 got a result 'o' which would be 2 (455 > & 302). I have tried different group by columns but to no avail. Can > someone help? >=20 > Thanks, >=20 > Richard >=20 > -- > MySQL General Mailing List > For list archives: http://lists.mysql.com/mysql > To unsubscribe: > http://lists.mysql.com/mysql?unsub=3Djason.trebilcock@stripped