SELECT p_id, SUM(qtyOld + qtyCurr) total
FROM (
SELECT p_id, 0 qtyOld, (order_p - totalStock) qtyCurr
FROM table
WHERE DATE_FORMAT(dates, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m')
UNION
SELECT p_id, totalStock qtyOld, 0 qtyCurr
FROM table
WHERE DATE_FORMAT(dates, '%Y-%m') = DATE_FORMAT(SUBDATE(NOW(),INTERVAL 1 MONTH), '%Y-%m')
) U
GROUP BY p_id
SELECT products_id, SUM(qtyOld + qtyCurr) total
FROM (
SELECT products_id, 0 qtyOld, (order_p - totalstock_products) qtyCurr
FROM table
WHERE DATE_FORMAT(date_insert, '%Y-%m') = DATE_FORMAT(NOW(), '%Y-%m')
UNION
SELECT products_id, totalstock_products qtyOld, 0 qtyCurr
FROM table
WHERE DATE_FORMAT(date_insert, '%Y-%m') = DATE_FORMAT(SUBDATE(NOW(),INTERVAL 1 MONTH), '%Y-%m')
) U
GROUP BY products_id