Sample Header Ad - 728x90

Select from other table if exist

0 votes
2 answers
1697 views
hi I want to union 2 tables but I am not sure if the table is exits this is my query: select a from table union select case when exists(select a from table1) then (select a from table1) else (select a from table2) end; got this > ERROR: ERROR 4840: Subquery used as an expression returned more than one row I need to use limit 1 in a subquery but it's not the result that I wanted. do you have other suggestions? thanks table, for example, I just created them in my local env for testing: table 1
CREATE TABLE public.table1 
(
    a int,
    b varchar(80),
    c int
);


CREATE TABLE public.table
    a int,
    b varchar(80),
    c int
);
Asked by NoamiA (101 rep)
May 11, 2020, 07:13 AM
Last activity: May 23, 2021, 11:33 AM