subquery with 3 different tables using ilike in postgres

0

Personal I have a question. How do I search for a particular text using ilike to know if this text exists in 3 related tables. I tried to exist but did not give

CREATE TABLE metodo (
    id SERIAL NOT NULL,
    descricao CHARACTER VARYING NOT NULL
);
CREATE TABLE forma (
    id SERIAL NOT NULL,
    id_metodo INTEGER,
    descricao CHARACTER VARYING NOT NULL
);
CREATE TABLE acao (
    id SERIAL NOT NULL,
    id_forma INTEGER,
    descricao CHARACTER VARYING NOT NULL
);
    
asked by anonymous 19.07.2017 / 22:36

1 answer

1

How about using UNION :

SELECT 'M', id, descricao FROM metodo WHERE descricao ILIKE '%texto%'
UNION
SELECT 'F', id, descricao FROM forma WHERE descricao ILIKE '%texto%'
UNION
SELECT 'A', id, descricao FROM acao WHERE descricao ILIKE '%texto%'
    
14.08.2017 / 22:24