Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create external links in SQL statements

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

What this article shares with you is about how to create external links in SQL sentences. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.

The creation of the external link of the SQL statement: the left link (left join), also known as the internal link (inner join). In this case, the data will be selected only if there is the same value in both tables. So what if we want to list every piece of data in one table, regardless of whether its value appears in another table or not? At this point, we need to use the SQL OUTER JOIN (external connection) instruction. The syntax of external connections varies from database to database. For example, on Oracle, we will add a "(+)" to the table where all the data are to be selected in the WHERE clause to say that we want all the data in this table.

Suppose we have the following two tables:

We need to know the turnover of each store. If we use a normal connection, we will miss the 'New York'' store because it does not exist in the Store_Information table. So, in this case, we need to concatenate the two tables with an external connection:

SELECT A1.store_name, SUM (A2.Sales) SALES FROM Georgraphy A1, Store_Information A2 WHERE

A1.store_name = A2.store_name (+) GROUP BY A1.store_name

We are using Oracle's external join syntax here. Results:

Store_name SALES

Boston $700

New York

Los Angeles $1800

San Diego $250

Note that when there is no relative data in the second table, SQL returns the NULL value. In this example, 'New York' does not exist in the Store_Information table, so its "SALES" field is NULL.

The above is how to create external links in the SQL statement. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report