View of two tables

0

I have two tables, TABLE_1 and TABLE_2 and I want to create a view with some fields of both where the id_event (existing in both) is equal.

CREATE TABLE table_1 (
    id INT,
    id_event INT,
    col1_t1 varchar(255),
    ...);

CREATE TABLE table_2 (
    id INT,
    id_event INT,
    col1_t2 varchar(255),
    col2_t2 varchar(255),
    ...);

The purpose is to have the view with the fields TABLE1.id, TABLE2.id, TABLE2.col1_t2 and TABLE2.col2_t2

    
asked by anonymous 02.09.2016 / 15:54

1 answer

1

Use INNER JOIN by comparing id_event to two tables:

SELECT T1.id, T2.id, T2.col1_t2, T2.col2_t2 
FROM table_1 AS T1
INNER JOIN table_2 AS T2
WHERE T1.id_event = T2.id_event 

Hugs.

    
02.09.2016 / 16:05