SELECT basics


By:
Overview

At the most basic level, a single column can be accessed from a SELECT statement. In this circumstance all of the values from the column will be returned from the table. From there you can expand into additional capabilities with the SELECT statement. Let's take a look at some examples.

Explanation

Let's start off by referencing the main components of a SELECT statement:

SELECT -- Column names
FROM -- Table or View name
WHERE -- Filter criteria
GROUP BY -- Logic to roll-up records
HAVING -- Criteria for GROUP BY logic
ORDER BY – Sort data either ASC (ascending) or DESC (descending) by column name or position

SQL Server SELECT with Single Column

-- Select first name from dbo.Authors table
SELECT FirstName
FROM dbo.Authors

SQL Server SELECT with Single Column and WHERE Clause

-- Select first name of authors as Jeremy from dbo.Authors table 
SELECT FirstName
FROM dbo.Authors
WHERE FirstName = 'Jeremy'

SQL Server SELECT with Single Column, WHERE and ORDER BY Clause

-- Select first name of active authors and return results in ascending order
-- from dbo.Authors table 
SELECT FirstName
FROM dbo.Authors 
WHERE ActiveFlag = 1 
ORDER BY FirstName ASC -- or DESC for descending results

SQL Server SELECT with Data Column and Count, WHERE, GROUP BY and ORDER BY Clause

-- Select first name with the associated count of active authors which also includes 
-- grouping the data by first name to roll-up the data and return results in 
-- descending order from dbo.Authors table 
SELECT FirstName, COUNT(*)
FROM dbo.Authors
WHERE ActiveFlag = 1
GROUP BY FirstName
ORDER BY FirstName DESC
Additional Information

This is just the tip of the iceberg, but a good first step to see how to use the SELECT statement in your applications and reporting.






Comments For This Article




Wednesday, September 11, 2019 - 9:23:24 AM - Jeremy Kadlec Back To Top (82364)

Perikay,

I am not familiar with SAP HANA SQL, but you may want to check out this resource from the vendor as a starting point:

https://help.sap.com/viewer/4fe29514fd584807ac9f2a04f6754767/2.0.03/en-US/20fcf24075191014a89e9dc7b8408b26.html

Thank you,
Jeremy Kadlec
Community Co-Leader


Wednesday, September 11, 2019 - 3:20:11 AM - PERIKA VIJAY Back To Top (82351)

good afternoon sir,

Dear sir may know the as same as this mssql tips for HANA SQL..

please help on this i am so many times in internet but i couldnt get the path yet..

but while following your mssql tips those were nice so i hope you can only help for my requirement so please help me to become good at SAP hana SQL 

thanking you sir


Saturday, January 23, 2016 - 10:56:45 AM - Arvind Nayan Back To Top (40483)

I Will study this and share the feedback with you.















get free sql tips
agree to terms