How to take data from 3 tables with INNER JOIN performatively

Asked

Viewed 1,797 times

-1

I got three tables on the bench, Exercise and Exercise. I need to do the SELECT with the INNER JOIN and differentiate columns with the same name:

    SELECT t.id AS tid, et.id AS etid, e.id as eid, t.data AS tdata, et.data 
         AS etdata, e.data as edata, *
    FROM treino t 
    INNER JOIN exercicio_treino et 
    ON et.treino = t.id 
    INNER join exercicio e 
    ON e.id = et.exercicio;

What I’d like to know is if it’s right to do it this way or if there’s a more practical way than typing all the columns in SELECT

2 answers

0

It is correct the way you are doing, I advise you only to do is to put more meaningful names to the alias, alias is the name you give to this table nickname, to facilitate your call.

SELECT column_name AS alias_name
FROM table_name;

More information

-2

Browser other questions tagged

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