- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the difference between DB2 JOIN and UNION? Explain with the help of an example
Both JOIN and UNION are used to combine the data from one or more tables. In case of JOIN, the additional data appears in column while in case of UNION additional data appears in rows.
Suppose we have two DB2 tables, ORDERS and TRANSACTIONS. We have to extract TRANSACTION_ID for each ORDER_ID, then we will use INNER JOIN as below:
SELECT ORDER_ID, TRANSACTION_ID FROM ORDERS INNER JOIN TRANSACTIONS ON ORDERS.TRANSACTION_ID = TRANSACTIONS.TRANSACTION_ID
This query will result in 2 columns. One column will be from ORDERS table i.e., ORDER_ID and other column will be from TRANSACTIONS table i.e. TRANSACTION_ID.
We have 2 tables ORDERS and ORDER_HIST. The ORDERS table has all the current orders while ORDER_HIST table has all the archived orders. If we want to list down all the orders having total value more than 10000, then we have to use the below query.
SELECT ORDER_ID, ORDER_TOTAL FROM ORDERS WHERE ORDER_TOTAL > 10000 UNION SELECT ORDER_ID, ORDER_TOTAL FROM ORDERS_HIST WHERE ORDER_TOTAL > 10000
- Explain join operations with the help of an example in DBMS
- What are COLUMN functions in DB2? Explain with the help of an example
- What is CLUSTERED INDEX in DB2? Explain with the help of practical example.
- What is the use of the VALUE function in a DB2? Explain with the help of an example
- Explain the concept of DYNAMIC SQL in DB2 with the help of an example
- What is NON CLUSTERED INDEX in DB2? Explain with the help of practical example
- What is the purpose of COALESCE function? Explain with the help of an example.
- Difference between UNION and UNION ALL in DB2
- What is Fixed-list SELECT? Give the syntax and explain with help of an example
- Explain SHARED, UPDATE and EXCLUSIVE locks with the help of an example
- Explain the concept of LOCK PROMOTION with the help of an example
- Difference between Join and union in SQL
- State the difference between structure and union with suitable example in C language
- What is the character count? Explain with an example?
- What is the difference between EXECUTE IMMEDIATE and EXECUTE WITH PREPARE in DB2?