Joins in HANA SQL
Joins are frequently used in database in SELECT statements to retrieve data from two or more tables.
Create below two tables in HANA database
Customer master table
Product Master table
|P5||Plain Paper A4 Size||2||NA|
You can create the table using the wizard or using plain SQL command window
Go through the video to understand these options.
Once the tables are created, you can analyze the data based on join conditions.
Joins can be created using SQL or using ‘Views’ option in hana studio.
Verify this with your results-
Inner join between customer and sales table will give 6 records (common data is returned)
Inner join between sales and product table will give 8 records (common data is returned)
Left Outer Join between Customer and Sales table with Customer as Left table will return 7 records (first it will return inner join records and then whatever extra data in Left table is also returned in the result set)
Right outer join between Customer and Sales table with Customer as Right table will return 8 records (first it will return inner join records and then whatever extra data in Right table is also returned in the result set)
Full Outer Join between Sales and Product table will give 9 records ( first it will return inner join records and then whatever extra data in Left table and extra in Right table are also returned in the result set)
Note: For above joins, there should be one common field between the tables on which join is applied
Union gives all the data from two table one after the other irrespective of common column is present or not.
The only criteria to apply union is that the structure of tables must be similar (same number of columns)
The result of union is all the records from both the tables one after the other.
UNION ALL is better performance wise as system does’nt remove duplicate data records here.
In UNION duplicate data records are removed and hence it takes more time to display the result set.
Apart from these we have some more joins in HANA which we will see in HANA modeling (star, referential, text, temporal etc.)