I'm attempting to return:
id | count | product | location
---------------------------------
123 | 10 | acme 1 | 1
---------------------------------
423 | null | null | null
---------------------------------
8766 | 3 | wiley 1 | 1
---------------------------------
5232 | 15 | wiley 2 | 1
---------------------------------
you can view the previous question here where I was able to return the data except that it won't return
id's
of items which do not return by the filter. The assumption is that id 423
does exist in the array as the filter is location = 1 and this particular id has the location identifier of 4
within the table. But I still want it in the returned resultset
I'm using:
SELECT
t.id
, count(t.id) total
, t.product
, t.location
FROM unnest(Array[123,423,8766,5232]::integer[]) id
LEFT JOIN inventory t
ON t.id IS NOT DISTINCT
FROM id.id
WHERE t.location_id = '1'
GROUP BY 1,3,4;
but it will only return the items which are listed in the request, not the full array of
id's
which I would like to automatically return 0
or null
I'm using PostgreSQL 9.4.x