¿Por qué no haces esto?: SELECT m.col1, (SELECT SUM(col5) FROM table WHERE col2 = m.col1) FROM table AS m