Join multi-table query

xiaoxiao2021-03-06  96

Use SQL statement connection table

In SQL, many power comes from connecting the information in several tables or queries and displays the result of a single logical recordset. Inn, including Inner, Left, Right, including Inner, LEFT, and Right. First let's talk about INNER JOIN: Inner Join statement can be used to combine records in the two tables, as long as there is a value that is consistent in the public field, in the syntax, Inner Join is defined in this way.

For example: We now have to connect the "Book Information" and "Publishing House Data Sheet" and then list the books from the publisher. Let's take a look at these two tables.

Then enter the following in the SQL design view

Now let's perform this SQL statement,

Discover the current query results column all publishers and books. This query seems to be implemented with the following statement.

After switching two queries to a data sheet view, we will find that the query results of the two queries are the same, but new data can be added in the query using the Inner Join operation. Just like adding data in the table. No new data cannot be added without using the Inner Join operation, compared to queries that use INNER JOIN operations more images that are connected to newly generated tables with associated contents. Knowing its use, let's take a look at Left Join Architecture: from [Table Name 1] Left Join [Table Name 2] ON [Name 1. Field a] [Table Name 2. Field B] In fact, the function of Left Join is to reserve all records in the left of the left left, and the field b in the table name 2 in the right is displayed in the record corresponding to the table name 1. Field a. Right Join and LEFT JOIN are the opposite. So the example just now can write:

Click the "Execute" button on the toolbar, we see the data sheet displayed at this time and the data sheet just shown in LEFT JOIN. I have seen it now, and their functions are to be interchangeable. If you want to join several tables, we can nested in Join operation, there are three tables: Table 1, Table 2, Table 3, now join three tables: from (Table 1 Inner Join table 2 on Table 1. Sequence number = Table 2. Serial number) Inner Join table 3 ON Table 1. Serial number = Table 3. The three tables in the serial number are connected.

转载请注明原文地址:https://www.9cbs.com/read-95979.html

New Post(0)