create view vwmerchant (
ID,
MERCHANT_ID,
REGISTER_ID,
ADQUIRENTE_ID,
DATA,
ACCESS_TOKEN,
AUTHORIZATION_CODE,
REFRESH_TOKEN,
EXPIRES_IN,
CLIENTE_ID,
CAIXABANCO_ID
)
as
SELECT
    *
FROM(
    select
        ID,
        MERCHANT_ID,
        REGISTER_ID,
        ADQUIRENTE_ID,
        DATA,
        ACCESS_TOKEN,
        AUTHORIZATION_CODE,
        REFRESH_TOKEN,
        EXPIRES_IN,
        CLIENTE_ID,
        CAIXABANCO_ID
    from tbcielo_merchant s
    where s.status = 'COMPLETED'
    
    union all
    
    select
        ID,
        MERCHANT_ID,
        REGISTER_ID,
        ADQUIRENTE_ID,
        DATA,
        ACCESS_TOKEN,
        AUTHORIZATION_CODE,
        REFRESH_TOKEN,
        EXPIRES_IN,
        MERCHANT_ID as CLIENTE_ID,
        CAIXABANCO_ID
    from tbrede_merchant s
    where s.status = 2
)
;

