4
How to create a select that lists at least 03 tables and presents a field from each table at least ?
4
How to create a select that lists at least 03 tables and presents a field from each table at least ?
4
In a relational database we store the data in tables. These tables relate through foreign keys (FK - Foreign Key).
Usually the primary key of one table will be present in another, which relates, in the form of foreign key.
An example is: We have 3 tables: buying, product and category.
produto_id
, that is primary key (PK - Primary Key) of product and foreign key in the buy table);To make a query that relates these 3 tables we have to use JOIN.
Here you can find Mysql documentation for the subject, but the concept is generic and applies to virtually all banks of dice (http://dev.mysql.com/doc/refman/5.7/en/join.html).
One SELECT
to illustrate:
SELECT c.data, c.valor, p.nome, ct.descricao
FROM tb_compra c
INNER JOIN tb_produto p ON p.id = c.produto_id
INNER JOIN tb_categoria ct ON ct.id = p.categoria_id
WHERE ct.id = 12;
The query brings the fields data
and valor
table buying, the field nome
table product and descrição
table category.
I hope I’ve helped.
Browser other questions tagged sql database firebird
You are not signed in. Login or sign up in order to post.
Do you have any questions or do you want to learn
select
? I recommend looking for a tutorial, there are several in Portuguese today: http://bfy.tw/6Mr4– Daniel Dutra
Start looking for John, I believe it helps you.
– Fbor