If you ask database professionals what the most important SQL statement is, they'll probably tell you that it’s the SELECT statement. The SELECT statement is at the core of all database applications. In its most basic form, the SELECT statement retrieves all of the rows and columns for a specified table. Here’s an example of the simplest type of SELECT statement:
SELECT * FROM AdventureWorks.Person.contact
The asterisk symbol (*) is SQL shorthand that indicates that all columns will be included. The FROM clause specifies the table that will be queried. In this example, the SELECT statement will retrieve all of the rows and columns from the Person.contact table in the AdventureWorks sample database.
You can also use the SELECT statement to perform row and column selection (hence the name ”SELECT” statement). In fact, it’s a bad practice to retrieve more data than your application needs, and using an unqualified SELECT statement such as the one in the previous example almost always retrieves more data than necessary. To perform basic row and column selection, you need to specify the desired column names immediately after the SELECT statement, then identify the rows that will be retrieved by using the FROM keyword, as you can see in the following example:
SELECT ContactId, Title, FirstName, LastName FROM AdventureWorks.person.contact WHERE Title = ‘Mr.’
In addition, a somewhat more advanced use of the SELECT statement is for table creation. By using the INTO clause, you can use the SELECT statement to create a new table based on the results being queried from an existing table. The following example shows you the basic use of the SELECT INTO statement to create a new table named NewContacts based on the results of the previous query.
SELECT ContactId, Title, FirstName, LastName
INTO NewContacts FROM AdventureWorks.person.contact
WHERE Title = 'Mr.'