194 Part I EXAM PREPARATION The SQL SELECT
194 Part I EXAM PREPARATION The SQL SELECT Statement Using the T-SQL SELECT statement is the most common way of accessing data. The majority of all data retrieval statements begins with these four fundamental parts of a SELECT operation: SELECT. Specifies the columns from the tables that need to be retrieved. FROM. Specifies where the table(s) and the columns are located. WHERE. Specifies a condition in order to filter data down. ORDER BY. Specifies how you want to order the data after it s been retrieved. The following code illustrates the use of the standard clauses within a SELECT query: EXAMPLE: SELECT * FROM Northwind.dbo.CUSTOMERS ORDER BY CompanyName (* retrieves all columns) SELECT statements can be made very complex with the use of options that can join many tables together and with functions that can calculate and summarize data at the same time. SELECT statements also can often be as simple as one line of code that retrieves the requested data. The complete SELECT syntax is very involved with many optional portions. The complete syntax reference can be found in SQL Server blogs Online (BOL) under SELECT, SELECT (described). Many of the options are used only under special circumstances. Take the following one-line code, for instance. Notice the simplicity required to code it and also note that at least the first two sub-statements are specified. SELECT * FROM Pubs.dbo.AUTHORS This statement retrieves all columns and rows from the authors table in the Pubs database. The SELECT statement s syntax is relatively simple as shown in the following: Select [all|distinct] columnlist From tablelist Where condition(s) OrderBy columnname type The descriptions for the arguments are shown in Table 4.1
For high quality java hosting services please check java web hosting website.