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 cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

aggregate combined with nonaggregate

Status
Not open for further replies.

paubad

Computer
Joined
Oct 26, 2006
Messages
2
Location
DK
I wish to perform a select in which I join two tables. I want to add an extra field telling me for each selected tuple from table 1 - how many tuples from table 2 were joined with it.

as follows:

table 1:

a %
b %
c +

table 2:

a 1
a 3
a 5
a 7
b 2
b 3
c 4
c 5
c 6

desired result:
a % 1 4
a % 3 4
a % 5 4
a % 7 4
b % 2 2
b % 3 2
c + 4 3
c + 5 3
c + 6 3

 
select t.f1,t.f2,f22, (select count(*) from tbl2 where f11=t.f1) as tuples from tbl1 t, tbl2 where f1=f11

f1 is field1 from tabl1
f2 is field2 from tabl1
f11 is field1 from tabl2
f22 is field2 from tabl2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top