Skip to content
Advertisement

Output records with null values even if not present

I have a table as below in Oracle

gen_id serial_code is_verified
1 fmcg Y
1 smcg Y
1 xmcg N
2 smcg Y
2 fmcg Y
2 2mcg Y
3 smcg Y
3 amcg Y

Now I want the output for max gen_id which is 3 in this case and serial_code ‘smcg’ and ‘fmcg’ I can get the output easily with queries but I want it in a format as below.

gen_id serial_code is_verified
3 smcg Y
3 fmcg not_present

How can i achieve this? Any help is much appreciated. Thanks in advance

Advertisement

Answer

You can use a PARTITIONed OUTER JOIN for this.

From Oracle 12:

In Oracle 11, you can use:

Which, for the sample data:

Both output:

GEN_ID SERIAL_CODE IS_VERIFIED
3 fmcg not_present
3 smcg Y

Oracle 18 db<>fiddle here – Oracle 11 db<>fiddle here

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement