View of two tables

Asked

Viewed 1,113 times

0

I have two tables, TABLE_1 and TABLE_2 and 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 aim is to have the view with the fields TABLE1.id, TABLE2.id, TABLE2.col1_t2 and TABLE2.col2_t2

1 answer

1


Use INNER JOIN comparing the id_event in both 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.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.