We have a table which holds the information about CUSTOMERS and the CONTACT NUMBER of the CUSTOMERS. So in table we have CUST_ID, CUST_NUMBER and CUST_OFF_NUMBER. For few CUSTOMERS, the NUMBER and OFFICE NUMBER is same and for few CUSTOMERS , NUMBER and OFFICE NUMBER is different. Below is the snapshot of the CUSTOMERS table:
The requirement is to fetch output in two columns (CUST_ID, CUST_NUMBER) such that if the CUSTOMER has same CUST_NUMBER and CUST_OFF_NUMBER then only one row should be present for the CUSTOMER however if the CUST_NUMBER and CUST_OFF_NUMBER are different then two rows should be present ; one for CUST_ID,CUST_NUMBER and second for CUST_ID,CUST_OFF_NUMBER. Below is the output which is required from the SQL Query.
Can you write the correct query? Leave your SQL Query as comment below. There may be several ways of getting the desired output. You can check the answer on ANSWERS PAGE too. However for better understanding of Teradata SQL , it is suggested that you leave a comment below with your SQL Query and then check our answer. We may get better and more ways of getting the result.
Hint: Try it via SQL Set Operators