Using the Using keyword in an Oracle connection (join) ____oracle

Source: Internet
Author: User

We introduced the use of natural join in Oralce, which is a natural connection. The Using keyword in a join connection in Oracle is relative to the natural join.

As we mentioned earlier, if you are using Natraul join, and if more than one field in two tables has the same name and data type, then the fields will be connected by Oracle.

But there are times when we don't need to connect like this. We just need to select one or two of their multiple fields with the same name and data type. At this point we need to use the Using keyword.

Here is an example.

In Oracle's example, the schema of SH has a table of sales, and a table is costs, and there are two fields in the two tables, pro_id and time_id respectively. For the moment, we do not consider the actual meaning of the connection below, only for grammatical research.

If you use a natural connection, by default two fields will be naturally connected together.

Select * FROM

Sales Natural join costs;

And

Select * FROM

Sales join costs on sales.prod_id = costs.prod_id and sales.time_id = costs.time_id

And

Select * FROM

Sales, costs

Where sales.pro_id = cost.prod_id

and sales.time_id = costs.time_id

The results should be the same.

If we use a natural connection, there is no chance to control the connection condition, and Oracle naturally joins the two fields of the same data type and name.

Let's use the Using keyword below.

Select * FROM

Sales join costs using (PROD_ID)

This forces Oracle to connect using the fields indicated by using, rather than the default two in the natural join connection.

Note that the SQL statement here does not make any sense, just to illustrate a far-fetched example of using usage.

Here's what you need to say:

1. If, when using the Using keyword, and the result list item for select contains the keyword specified by the Using keyword, do not indicate in the result list item of the Select which table it belongs to, such as if using using (prod_id), To include the prod_id field in the results list, do not write sales.prod_id or costs.prod_id instead of prod_id, and do not use aliases, such as the prod_id as "product number" form.

2. Only one column name can be used.

The 3.natural join keyword and the Using keyword are mutually exclusive, meaning they cannot occur simultaneously.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.