Change the jos_ prefix to the prefix you are using.

-- add tags to all products from selected category (a.id ... product, 4 ... tag ID, c.id ... category ID)
REPLACE into jos_phocacart_tags_related (item_id, tag_id)
SELECT a.id, 4
FROM jos_phocacart_products a
LEFT JOIN jos_phocacart_product_categories AS pc ON pc.product_id = a.id
LEFT JOIN jos_phocacart_categories AS c ON c.id = pc.category_id
WHERE c.id = 1