How to display 2 columns from 2 different tables in MySQL?


I have 2 tables with multiple columns.

I would like it to display individual columns from more than one table at the same time:

tabela1 | tabela2

Nome    | Apelido


There's not much secret:

SELECT tabela1.nome, tabela2.apelido FROM tabela1, tabela2;

I put it on GitHub for future reference .

After SELECT you will put the list of columns you want to be shown. When there is more than one table, it is important to qualify the column completely, that is, say which table the column belongs to, in other words, give it a last name, so it is more obvious where this column comes from and avoids ambiguity if the tables have columns with the same name. In some cases the table name can be omitted but it is usually interesting to put it anyway.

After the FROM clause you list all the tables that should be available in the query. Without this you will not be able to use them for all operations. It is possible to create an alias for the table name as demonstrated in another answer but it doesn't matter for what you want. It's just an ease when you're going to use the table name many times.

Scroll to Top