I have recently faced a query which has been written longtime ago for an Informix database. This query seems a bit strange and nonsense to me.
I know This query returns all the rows from the city table
with the rows that match in the ocw table
. If no record for a city
appears in the ocw table
, the returned code column
for that city has a NULL
value.
I understand also that UNION
removes duplicates, whereas UNION ALL
does not.
Is my understanding about outer
and union all
correct?
Can anyone explain what they try to achieve with this query and is there a better way to do this?
SELECT * FROM city as c, OUTER ocw o
WHERE c.mutual = o.code
INTO temp city_ocw;
SELECT
name ,
year ,
mutual ,
0 animalId
FROM
city_ocw
WHERE
code IS NULL
GROUP BY
1, 2, 3 , 4
UNION ALL
SELECT
name ,
year ,
mutual ,
animalId
FROM
city_ocw
WHERE
NOT code IS NULL
GROUP BY
1, 2, 3 , 4
INTO TEMP city_ocw_final ;