This SAP HANA tutorial explains how to write a select statement in the Cloud version of SAP HANA. Also, this post will help you to show how to insert values and how to use the where condition in SAP HANA.
What is Select Statement in SAP HANA
The Select statement in SAP HANA shows the result or output in a table. Also, it is to show specific records as well using where conditions.
Example: We want to see the output for the table like VendorDetails at that moment, we will use a select statement in SAP HANA. See the below image for an understanding.
The SELECT statement is used to pick data from a HANA database. The data returned is stored in a result table, called the result set.
- The SELECT command is the most important statement for any data analysis because it reads data from tables.
- After SELECT, the symbol * denotes that all fields from this table are required. This means all the values will be shown in the output table of SAP HANA.
- System statements, keywords, and functions are always displayed in a reddish-pink color, while table names and string values are typically displayed in blue.
- The color of integer values and mathematical symbols is often black. The table name should always be provided as it is. Also, if we have only one SQL statement, we can omit the semicolon at the end of the statement.
- Press the execute button or click F8 in the SQL editor to run the command. Check below the vendor table image for color variation.
This is what the vendor detail table in SAP HANA to show the color variation for the data types.
Also, Read: How to Create a Foreign Key in SAP ABAP
How to Use Select Statements in SAP HANA?
Here the table name is VendorDetails, we will see the syntax for the tables below.
- The syntax for the VendorDetails is as follows:
SYNTAX: SELECT * FROM TABLE NAME
- To get or see the table, we have used a select statement. Check the below image for your reference.
This is the standard method to check the table by using the Select statements in SAP HANA.
Insert Values in Table in SAP HANA
Here, we’ll see how to add values to VendorDetails tables and check the results of a select statement.
- Below we have added values in the table. We will see how to see that output in the forthcoming topics.
Insert into VendorDetails values(45623, 'benjamin','alexander city','sanfransisco','35010','cash'), values(67234, 'alexa','lake city','sanfransico','35011','digital')
- Below are the values we should add to the table using a select statement.
45623, ‘benjamin’, ‘alexander city’, ‘sanfransisco’, ‘35010’, ‘cash’ = Specify the values enclosed with a single inverted comma (“).
- The syntax for selecting the whole values from the VendorDetails is as follows:
SELECT * FROM VendorDetails
VendorDetails = Table name
Doing this standard method, we will see the output through the select statement.
Have a look: How to Create SAP ABAP List View Report (ALV)
Select Statement For Specific Column in SAP HANA
Here we will see how to see the particular column to get the output in SAP HANA.
- For example, if I want to see only the vendor name from the table, below are the syntax and screenshots.
SELECT vendor_Name FROM VendorDetails;
This is how we have to use a select statement to get the one column in SAP HANA.
Select Statement by using Where Condition in SAP HANA
If we want to select or see a particular column with the inserted fields use the where condition in SAP HANA.
- Below is the syntax for the where condition. For example, if I want to see only the first row’s vendor ID, see the syntax below.
SYNTAX - Select * FROM VendorDetails where vendor_id='45623'
In this method, we can select all the columns through one vendor value in SAP HANA Cloud.
Select the Top 1 statement in SAP HANA Cloud
Now we will see if the SAP HANA database has large numbers of values, but we want to pick the top 1 values.
- Here I have chosen the top 1 values of vendor city and state details alone. This means 1st value is only displayed at the output. Check the below image with the output.
SELECT TOP 1 vendor_city, vendor_state FROM VendorDetails
This is the method to see how to select the top 1 values in SAP HANA.
You may also like:
- SAP HANA Cloud ABAP Environment
- What is SAP HANA Cloud Data Lake
- What is SAP HANA Cloud & How it Works [With Features]
I trust this article explained enough information for select statements in SAP HANA Cloud. This tutorial also touched upon different scenarios to use select statements in SAP HANA. Below are the topics covered in this tutorial.
- What is a select statement in SAP HANA?
- How to use Select statement in SAP HANA?
- Insert Values in a table for select statement
- Select statement only particular column in SAP HANA
- Select a statement by using Where Condition in SAP HANA
- Select the Top 1 statement in SAP HANA Cloud
I am Chris Waldron, working as a Senior SAP HANA Consultant at Halliburton, Houston, Texas, United States. I have been working in SAP for more than 15 years, especially in SAP IT consulting and business consulting. I worked in various industries in Sales & Distribution, Customer Relationship Management, banking, Risk Management, etc. And I am an SAP Certified Development Specialist – ABAP for SAP HANA 2.0 and SAP HANA Modeling Certified consultant. Read more