All,
I am novice in SQL/MySQL. I need a query to join two tables say table1 and table2. But the join should happen not based on PK, but based on other columns, which are non-unique. One of the columns joined in table2 is sum of all the numbers in a column, when the clause is satisfied. For example here are the tables:
table1:
tab1id, tab1no, tab1name,tab1va l
1,'01','one',10 0
2,'01','two',20 0
10,'02','ten',3 00
11,'02','eleven ',400
table2:
tab2id,tab2no,t ab2name
3,'01','three'
12,'02','twelve '
Now, I need a resulting table (after join) as this:
3,'01','three', 300
12,'02','twelve ',700
the fourth column is SUM(tab1val), when table1.tab1no = table2.tab2no.
Thank you,
Giri
I am novice in SQL/MySQL. I need a query to join two tables say table1 and table2. But the join should happen not based on PK, but based on other columns, which are non-unique. One of the columns joined in table2 is sum of all the numbers in a column, when the clause is satisfied. For example here are the tables:
table1:
tab1id, tab1no, tab1name,tab1va l
1,'01','one',10 0
2,'01','two',20 0
10,'02','ten',3 00
11,'02','eleven ',400
table2:
tab2id,tab2no,t ab2name
3,'01','three'
12,'02','twelve '
Now, I need a resulting table (after join) as this:
3,'01','three', 300
12,'02','twelve ',700
the fourth column is SUM(tab1val), when table1.tab1no = table2.tab2no.
Thank you,
Giri
Comment