SELECT DISTINCT and SELECT TOP
SELECT DISTINCT
The Select
starter class has three methods you can use to create select statements: All()
, which you’ve already seen, Distinct()
, and Top()
.
Select.Distinct()
works exactly the same way as Select.All()
but removes duplicate rows from the result set.
var selectStatement = Select.Distinct("Name")
.From("Customer");
SELECT DISTINCT [Name]
FROM [Customer];
SELECT TOP
You can add a TOP
clause to your select statement with Select.Top()
. Top()
supports returning an absolute number of rows, a percentage, and the WITH TIES
modifier. You can build the method chain in the same order that you’d write the SQL statement.
var selectStatement = Select.Top(10).All("Name")
.From("Customer");
The Top()
method can take an integer (int
or long
) or a Percentage
argument. A Percentage
object is created with the Percent()
extension method on numeric types.
var selectStatement = Select.Top(10.Percent()).All("Name")
.From("Customer");
The WithTies()
modifier is chained the same way.
var selectStatement = Select.Top(10).WithTies().All("Name")
.From("Customer");