Trying to find the items where origin_id is null and have it show the count where other rows in the same table have its id as origin_id set.
This query returns 0 for all 🙁 ?
SELECT
id,
source_url,
origin_id,
(SELECT
COUNT(*)
FROM
queue_items
WHERE
queue_items.origin_id = queue_items.id) AS originCount
FROM
queue_items
WHERE
origin_id IS NULL
2
Answers
The subquery try to compare the originalid of the same table as id.
you need aliases to differentiate the tables
This can be done using
self left join
andgroup by
:Demo here