I have this SQL query (for SQL Server)
SELECT job.id AS job_id,
( SELECT STRING_AGG( ISNULL(goods_rif.rif_car, ''), ',')
FROM goods_rif WHERE job.id = goods_rif.job_id
) AS goodsrifcar
FROM job
WHERE ( job.job_creation_date >= DATEADD( DAY, -10, GETDATE() ) )
ORDER BY job.id DESC
which works as expected.. but if I add a query clause (AND goodsrifcar= 'xxx') I get: invalid column name goodsrifcar
SELECT job.id AS job_id,
( SELECT STRING_AGG( ISNULL(goods_rif.rif_car, ''), ',')
FROM goods_rif WHERE job.id = goods_rif.job_id
) AS goodsrifcar
FROM job
AND goodsrifcar= 'xxx'
WHERE ( job.job_creation_date >= DATEADD( DAY, -10, GETDATE() ) )
ORDER BY job.id DESC
p.s. the sub query (... SELECT STRING_AGG...) only performs a concatenation of values from the "goods_rif" table