Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add column with count of how many there are inside to the distinct group

Status
Not open for further replies.

Crox

Programmer
Apr 3, 2000
892
NL
Hi,

I have a case with two tables to join and three of the columns of the first table should be distinct. I want those three columns and one column of the second table and the count of how many rows there are inside of the distinct group.

So table TA contains A, B, C, D

table TB contains B, E

how to get the distinct (A, B, C) and E and the count of the rows inside of the distinct (A, B, C).

Thanks very much for any help!

Regards,

Crox
 
untested:

select ta.a, ta.b, ta.c, bcount from ta
where bcount = (select count(*) from tb
where ta.b = tb.b)

btw, this is not DB2 specific, so the question could also be asked in the ANSI_SQL forum, or an Oracle or SQL Server forum. Those forums are more heavily travelled within Tek-Tips than this one.

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top