clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3364508 fiddles created (36236 in the last week).

create table my_table(post_id integer, org_id integer);
 hidden batch(es)


insert into my_table(post_id,org_id) select level, 1 from dual connect by level<5 union all select level, 2 from dual connect by level<5;
8 rows affected
 hidden batch(es)


SELECT * from my_table;
POST_ID ORG_ID
1 1
2 1
3 1
4 1
1 2
2 2
3 2
4 2
 hidden batch(es)


SELECT coalesce(MAX(post_id),0) AS max_id FROM my_table WHERE org_id = 3
MAX_ID
0
 hidden batch(es)


insert into my_table(post_id,org_id) select null, 3 from dual;
1 rows affected
 hidden batch(es)


SELECT coalesce(MAX(post_id),0) AS max_id FROM my_table WHERE org_id = 3;
MAX_ID
0
 hidden batch(es)


SELECT case count(*) when 0 then 0 else MAX(post_id) end AS max_id FROM my_table WHERE org_id = 3;
MAX_ID
 hidden batch(es)