Hi, I have tables like this:
entry in the table:
id | total_comments
_____________________
1 | 0
2 | 0
3 | 0
4 | 0
comments in the table:
id | eid | a comment
_____________________
1 | 1 | comment sdfd
2 | 1 | testing testing
3 | 1 | comment text
4 | 2 | fictitious comment
5 | 2 | sample comment
6 | 1 | fg fgh dfh
Request I write:
UPDATE entry SET total_comments = total_comments + 1 WHERE id IN ( SELECT eid FROM comments WHERE id IN (1,2,3,4,5,6))
Results:
entry in the table:
id | total_comments
_____________________
1 | one
2 | one
3 | 0
4 | 0
Expected results:
entry in the table:
id | total_comments
_____________________
1 | 4
2 | 2
3 | 0
4 | 0
Any help would be appreciated.
mysql sql-update sql-view subquery
Johal
source share