You can do it this way:
SELECT
tbl_purchase_product.sub_total + tbl_purchase_product.others_price as sub_total
FROM
(`tbl_purchase_product`)
WHERE
`tbl_purchase_product`.`purchase_id` = '3'
As you are searching for the id I believe you need to add only this record, but if you want to add of all, you can do as follows:
SELECT
sum(tbl_purchase_product.sub_total + tbl_purchase_product.others_price) as sub_total
FROM
(`tbl_purchase_product`)
WHERE
`tbl_purchase_product`.`purchase_id` = '3'
Some example to indicate what your problem is
Imagine the following example:
ID VALUE1 VALUE2
===================
1 1 2
1 2 2
2 3 4
2 4 5
If you do the following query:
SELECT ID, SUM(VALUE1), SUM(VALUE2)
FROM tableName
GROUP BY ID
The result will be:
ID, SUM(VALUE1), SUM(VALUE2)
1 3 4
2 7 9
While if you do it this way:
SELECT ID, VALUE1 + VALUE2
FROM TableName
The result will be:
ID, VALUE1 + VALUE2
1 3
1 4
2 7
2 9
And on the other hand doing it this way:
SELECT ID, SUM(VALUE1 + VALUE2)
FROM tableName
GROUP BY ID
The result:
ID, SUM(VALUE1 + VALUE2)
1 7
2 16
Source
Update
Reply after clarification in the comments
SELECT
sum(tbl_purchase_product.sub_total) + tbl_purchase_product.others_price as sub_total
FROM
(`tbl_purchase_product`)
WHERE
`tbl_purchase_product`.`purchase_id` = '3'
sum(tbl_purchase_product.sub_total) + sum(tbl_purchase_product.others_price) as sub_total
?– Roberto de Campos
I’m not sure that works:
sum(tbl_purchase_product.sub_total + tbl_purchase_product.others_price) as sub_total
but I believe so– Roberto de Campos
You need to add to each line, or you need the total amount?
– Marciano Machado
I just wanted to add + others_price, I don’t want to add everything you have in the field...
– Sr. André Baill
@Mr Andrébaill, if any of the answers are correct, mark it as such! Why it is important to vote?. Also give an UP to the answers that have been useful to you.
– João Martins