
Understanding SELECT SQL Statement Command |
Although there are optional clauses of the SELECT statement, a SELECT statement must consist of at least SELECT List FROM Table Name. Each capitalized keyword in a SELECT statement is referred to as a clause. A SELECT statement must contain a SELECT and FROM clause, whereas the WHERE and ORDER by BY clauses are optional.
The select List contains a comma-delimited list of the columns that want to return, whereas the Table Name is the name of the table from which you want to retrieve data.
The Data Present in the Products Table
Product ID....................
Name.................... Price.................... Inventory
1.................................
Monitor................... 195.95................... 100
2.................................
Mouse......................... 9.95 ...................250
3.................................
Keyboard.................. 24.95..................... 55
4.................................
Scanner ...................149.50..................... 15
5.................................
CD-ROM................. 79.95..................... 75
6.................................
Printer..................... 155.50..................... 19
7.................................
Sound Card.............. 29.45...................... 34
8.................................
Game Pad................. 29.50................... 190
9.................................
Zip Drive................. 129.95...................... 7
10................................Modem.....................
89.90................... 190
If you wanted to create a SQL statement that would retrieve every column from the products table, the select List would need to contain each column of the table, each separated by a comma. The following example returns all the rows and columns in the products table:
SELECT
Product ID, Name, Price, Inventory
FROM Products
If you want to obtain all the columns, you can use the asterisk (*) in the select List to denote that you want to include all the columns. The following two SQL statements are functionally equivalent:
1.
SELECT Product ID, Name, Price, Inventory FROM Products
2. SELECT * FROM Products
Note
that line 2 uses an asterisk in place of all the column names. Both SQL statements
return all the columns and rows of the products table.
If you wanted to
retrieve just the Name of all products, you could modify the SQL statements
select List to contain just the Name column:
SELECT Name FROM Products
If you wanted to obtain just the Name and Price of all products, you could add the Price column to the select List:
SELECT
Name, Price FROM Products
_______________________________________________________________________
FREE
Subscription
Subscribe to our mailing list and receive new articles Note
: We never rent, trade, or sell my email lists to Visit
.NET Programming Tutorial Homepage ______________________________________________________ Recommended
Resource
through email. Keep yourself updated with latest
developments in the industry.
anyone.
We assure that your privacy is respected
and protected.