I have got a table which i have mentioned below, i need to get a total results avoiding duplicates , can any one provide any assistance or suggestions on how to get the results mentioned below, thankyu
ID name Total Used
24 John 5 2
24 John 10 6
27 Peter 20 0
27 Peter 20 5
Result should be something like this
ID name Total Used
24 John 15 8
27 Peter 40 5
Looks like you just need to use
SUM()on the two columns. Also use aGROUP BYon the id and namesee SQL Fiddle with Demo
The
GROUP BYfield must include any other columns you are selecting which are not in an aggregate function, so for the example you would include bothidandnamein theGROUP BY.Edit #1 your query would be: