Differences between intra-database connections, full connections, and left-right connections

Source: Internet
Author: User

We often use joint queries for two tables. Sometimes we use internal connections, full connections, and left and right connections. Is it very complicated? The following is a demonstration of their differences.

First, there are two tables:

 
 
  1. CREATE TABLE weather  
  2. (  
  3.   city character varying(80) NOT NULL,  
  4.   temp_lo integer NOT NULL,  
  5.   temp_hi integer NOT NULL,  
  6.   prcp real,  
  7.   date date 
  8. )  
  9. WITH (  
  10.   OIDS=FALSE 
  11. );  
  12. ALTER TABLE weather OWNER TO postgres;  
  13. -----------------------------------------------------------  
  14.  
  15. REATE TABLE cities  
  16. (  
  17.   "name" character varying(80) NOT NULL,  
  18.   "location" point  
  19. )  
  20. WITH (  
  21.   OIDS=FALSE 
  22. );  
  23. ALTER TABLE cities OWNER TO postgres; 

Let's look at the data.

Next we start the internal connection. You don't need to explain it too much. You can see what's going on in the picture.

As you can see, inner and select * from weather, cities where city = name have the same output, all of which correspond to one-to-one output. I like it!

Next let's take a look at the picture of the full connection and left and right connections.

As you can see, full join means that all the data in the two tables is listed. If there is no data in the table, leave it blank.

I think this is the case when the left and right join is a fully connected subset.) The left join is used as the reference, and the back table does not have data completing control.

After the right join is completed, the table is used as the benchmark. If the former table does not exist, it is null.

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.