JOIN operation in HQL

JOIN operation in HQL:

Hive supports multiple JOIN methods to connect multiple tables to perform complex query operations, including INNER JOIN, LEFT JOIN, RIGHT JOIN, FULL OUTER JOIN, CROSS JOIN and SELF JOIN, etc.

  1. INNER JOIN
  2. LEFT JOIN
  3. RIGHT JOIN
  4. FULL OUTER JOIN
  5. CROSS JOIN
  6. SELFJOIN

Example:

The following examples illustrate the use of various JOIN methods:
Assume there are two tables: orders table and customers table.
The orders table contains order information, including fields such as order number, customer ID, order time, and order amount.
The customers table contains customer information, including fields such as customer ID, customer name, contact information, and address.

Now you need to query the customer name and contact information for each order.

1. INNER JOIN

Using the INNER JOIN method, you can connect records with the same customer ID in the orders table and customers table:

SELECT o.order_id, c.customer_name, c.contact_info
FROM orders o
INNER JOIN customers c
ON o.customer_id = c.customer_id;

2. LEFT JOIN

Using the LEFT JOIN method, you can connect all records in the orders table with matching records in the customers table, and return NULL values ​​if there are no matching records in the customers table:

SELECT o

Guess you like

Origin blog.csdn.net/Wxh_bai/article/details/130072828