Understanding SELECT SQL Statement Command

SQL statements can be used to update, insert, delete, and query data. We will narrow our focus to querying data, and not drill down to the acute specifics. Whenever you want to obtain data from a table in your database, you need to use a SELECT statement, which has the flowing form:


SELECT selectList
FROM TableName
[ WHERE searchClause]
[ ORDER BY orderExpression [ASC ; DESC]]

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 statement’s 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

| All about Conceptual Analysis on .NET Remoting | Building desktop applications in .Net | Building Distributed Applications Efficiently Using .Net Remoting | C# (C Sharp) Unified Type System: Reference Types | C# (C Sharp) Unified Type System: Value Types | Data access in .Net | Delegates Vs Interfaces in C# (C Sharp) | How is Integration between Java and .NET Achieved | How is Versioning Achieved in C# (C Sharp) | Implementing Authorization and authentication in ASP.net | Implementing design patterns in .Net | List of Query Keywords in C# (C Sharp) |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.