Sunday, May 9, 2021

SQL Server Select Statement

SQL Server select statement Retrieves rows from the database and enables the selection of one or many rows or columns from one or many tables in SQL Server. 

The full syntax of the SELECT statement is complex, but the main clauses can be summarized as:

SELECT select_list 

FROM table_source ] [ WHERE search_condition ]

GROUP BY group_by_expression ]

HAVING search_condition ]

ORDER BY order_expression [ ASC | DESC ] ]

The data returned is stored in a result table, called the result-set.

Select Statement Example:

USE AdventureWorks2017;
GO
SELECT *
FROM Production.Product
ORDER BY Name ASC;

 -- Alternate way.

USE AdventureWorks2017;
GO
SELECT p.*
FROM Production.Product AS p
ORDER BY Name ASC;




Adding Column name in select list

USE AdventureWorks2017;
GO
SELECT Name, ProductNumber, ListPrice AS Price
FROM Production.Product 
ORDER BY Name ASC;


USE AdventureWorks2017;
GO
SELECT Name, ProductNumber, ListPrice AS Price
FROM Production.Product 
WHERE ProductLine = 'R' 
AND DaysToManufacture < 4
ORDER BY Name ASC;


 

No comments:

Post a Comment