Presentation is loading. Please wait.

Presentation is loading. Please wait.

SELECT & FROM Commands Farrokh Alemi, PhD

Similar presentations


Presentation on theme: "SELECT & FROM Commands Farrokh Alemi, PhD"— Presentation transcript:

1 SELECT & FROM Commands Farrokh Alemi, PhD
This set of slides were organized by Professor Alemi and describe how to filter columns in SQL by using the select command.

2 Filter Data The select command is the most common command in SQL. It is almost always used in data manipulation codes. Its purpose is to filter data. It focuses the analysis on columns of data, i.e. fields, from a table.

3 SELECT column1, column2, ... FROM table_name;
Here is the syntax of the select command.

4 SELECT column1, column2, ... FROM table_name;
Separated by Comma Select command is usually followed by one or more field names separated by comma.

5 Specifies Existing Table
SELECT column1, column2, ... FROM table_name; Specifies Existing Table The FROM portion of the command specifies the table it should be read from.

6 SELECT id, firstname FROM #temp
Here is an example. Here we see the select command asking the software to report on a variable/field called “id” and another called “firstname.” These variables are read from a table called hash tag temp.

7 SELECT * FROM #temp If necessary, the field names can be replaced with *, in which case the select command will list all fields in the table. This command tells the server to return the top 20 rows of data from the temporary file hash tag temp. The top 20 modification of the select command is used to restrict display of large data and enable faster de-bugging.

8 USE Database1 The prefix to a table must include the name of the database. To avoid doing so repeatedly, the name of database is defined at start of the code with the USE command. Here the code is instructing the computer to use tables in Database one.

9 FROM dbo.data In addition, the query must identify the type of table that should be used. The place where a table is written is dictated by its prefix. A prefix of dbo indicates that the table should be permanently written to the computer data storage unit. This command says that the query is referencing the permanent table named data.

10 FROM #data The hash tag preceding the table name says that the query is referencing a temporary table.  These types of tables disappear when the query that has created it is closed. These data are not written to the computer’s storage unit.

11 FROM ##data A double hash tag indicates a temporary file that can be referenced from multiple queries. The table is temporary but is available to all open windows of SQL code, not just the window that created it. This is particularly helpful in transferring temporary data to procedures.

12 Thus, single hash tag prefix indicates a temporary local file, double hash tag prefix indicates a global temporary file, and prefix dbo marks a permanent file.

13 SELECT FROM SELECT command specifies the fields and FROM command the table and location of the table.


Download ppt "SELECT & FROM Commands Farrokh Alemi, PhD"

Similar presentations


Ads by Google