Reputation: 159
I have multiple tables, I can list their rows to my website.
What I want is where last column has same value, I want to add up rows values and list as one line.
What I have:
Hioss
AUR
Top
1
1
0
Shen
Hioss
AUR
Top
1
1
0
Shen
Kanani
AUR
Jungle
1
1
0
Reksai
I don't want to get data like this. If last column has same values (Shen) I want to sum int values and show as one line at my website.
What I want to do:
Hioss
AUR
Top
2
2
0
Shen
Kanani
AUR
Jungle
1
1
0
Reksai
My mysql query:
mysql_query("SELECT * FROM table1 UNION SELECT * FROM table2");
How can I do it? What should I do?
Upvotes: 1
Views: 47
Reputation: 15057
Try this. i dont know the fieldnames. You must change it
SELECT fieldnam1,fieldnam2, sum(fieldnam3),fieldnam4
FROM (
SELECT * FROM table1
UNION
SELECT * FROM table2
) as result
GROUP by fieldnam4;
Upvotes: 1