Do SQL query in 3 tables and return the value to another table? [closed]

-1

I have 3 tables (A, B, C) with column descricao (with different records between them).

I want to make SELECT of the three tables and send the result to another table D.

It would be something like this:

SELECT A.descricao, B.descricao, C.descricao FROM A, B, C JOIN D
    
asked by anonymous 02.10.2015 / 17:45

2 answers

2

To insert the result of a SELECT into another table you can do this:

INSERT INTO D (descricaoA, descricaoB, descricaoC)
SELECT A.descricao, B.descricao, C.descricao FROM A,B,C

Since table D has the following format:

| descricaoA | descricaoB | descricaoC |
|------------|------------|------------|
|            |            |            |
    
02.10.2015 / 18:14
0

You can create a view for this:

DROP VIEW IF EXISTS view_D;
CREATE VIEW view_D AS
SELECT descricao FROM tab_A
union
SELECT descricao FROM tab_B
union
SELECT descricao FROM tab_C;

Then select the data from this view:

Select * from view_D;
    
24.05.2016 / 23:30