YUI 2.4.0 Finally Released! Microsoft Live Labs Volta
Dec 04

Bill Horst continues with those simple examples. After this one here comes the other set. They are perfect to show basic syntax. Here are few more:

DISTINCT
SQL SELECT statements can include the DISTINCT specifier, which causes all duplicate records in the query result to be removed. In a LINQ expression, Distinct is its own individual clause, rather than a specifier on the Select clause. This means that Distinct can appear between any two other clauses. The Distinct clause takes whatever result is returned by the preceding clause (Select, in the case below) and returns a filtered result with duplicates removed. To two code examples below accomplish the same results:

SQL

SELECT DISTINCT Name, Address
FROM CustomerTable

VB

From Contact In CustomerTable _
Select Contact.Name, Contact.Address _
Distinct

ORDER BY
The SQL ORDER BY clause can also be represented in a LINQ expression. A LINQ Order By clause allows for a comma-delimited list of expressions to specify how results should be sorted. Any valid VB expression can be used, so these expressions don’t necessarily have to be the names of field that were selected.

SQL

SELECT * FROM CustomerTable
ORDER BY Phone

VB

From Contact In CustomerTable _
Order By Contact.Phone

ASC/DESC
A SQL ORDER BY clause can also include ASC and DESC keywords, to specify that the sort should be in ascending or descending order, respectively. VB uses Ascending and Descending keywords for the same purpose, with the same syntax. If neither specifier is present, ascending order is the default.

SQL

SELECT * FROM CustomerTable
ORDER BY Phone ASC, Name DESC

VB

From Contact In CustomerTable _
Order By Contact.Phone Ascending, Contact.Name Descending

Here is the original post by Bill Horst

Leave a Reply