..


Sponsored Links

How do I create a query on more than two tables?

To create a relationship between more than two tables in SQL we can use the traditional method, or the JOIN statement.

Imagine the following tables, composed of the respective fields:

  • authors
    • aut_id
    • aut_nome
  • publishers
    • edi_id
    • edi_nome
  • books
    • lib_id
    • lib_autore
    • lib_editore
    • lib_titolo
The field lib_autore, numerical, will have the same value as the id of the author of the homonymous table. The same holds true for the field lib_editore.

We see the classic method to write the SQL code:





 SELECT * FROM authors, publishers, books







 WHERE







 aut_id = lib_autore







 AND







 edi_id = lib_editore



We see the method that provides education JOIN:





 SELECT * FROM authors







 INNER JOIN books







 ON = autori.aut_id libri.lib_autore







 INNER JOIN publishers







 ON = libri.lib_editore editori.edi_id



In the same category ...
E-Learning
MS Access (Advanced) MS Access (Advanced)
Learn how to create and manage databases quickly and easily. Starting from 29 €.
MySQL (Course) MySQL (Course)
Management of open-source database. From 39 €.
SQL and Database (Course) SQL and Database (Course)
Create and manage relational databases. From 39 €.
Sponsored Links