


LEFT JOIN offices ON panies_id = companies.id Therefore, any result of the query with tables from this example will always include the below lines: SELECT If the tables with the required data are not directly related to each other, you also need to include the intermediate tables that join them.įor this reason, we also connect tables, such as offices and customers, using foreign keys. The example above involves the companies and calls tables. Let’s try to create a multipurpose algorithm for composing complex queries.įirst of all, you need to decide on the tables consisting of the data that takes part in the query. What Are the Main Rules for Creating Complex SQL Query? The table shows the companies, the corresponding number of phone calls, and their approximate duration.įurther, it lists only those company names where the average call duration is greater than the average call duration in other companies. We will consider this in detail further with an example: The first line is the name of the table that in complex queries acts as a foreign key. To better understand the topic, let’s consider an example that uses the following four simple tables.
#NINOX COMPOSITION HOW TO#
This article will explain how to build such queries and provide examples of complex SQL queries. When the data for a query is not in one table, but in several, or when it is necessary to specify several selection parameters at once, you will need more sophisticated queries.

Typical queries in the SELECT * FROM table format are sometimes not enough.
