Or operator in SQL where choose clause


  • 2 minutes to read

Specifies the items returned by a query.



Indicates that duplicates are allowed in the result set. ALL is the default.

Indicates that only unique results are allowed in the result set.

Allows you to specify only one element and does not add a row wrapper.

Any valid expression of the form that indicates the number of results to be returned by the query.

You can also select the first n elements of the result set with the limit parameter of the Order by operator.

An expression of the form:

like |

A literal or an expression.


The SELECT clause is evaluated after the from, group by, and have clauses have been evaluated. The SELECT clause can only refer to elements currently in the range (the FROM clause or outside ranges). If a GROUP BY clause is specified, the SELECT clause can only refer to the aliases of the GROUP BY keys. References to elements of the FROM clause are only allowed in aggregate functions.

The list of one or more query expressions that follow the SELECT keyword is called a select list or a projection. The most common form of projection is a single query expression. Selecting a member from a collection creates a new collection of all the values ​​for each object in. This is shown in the following example.

If z. For example, if a collection is of the type that has the property of Type, selecting off creates a collection of strings. This is shown in the following example.

JOIN syntax (FULL, INNER, LEFT, OUTER, ON and RIGHT) can also be used. ON is required for inner joins and not allowed for cross joins.

Row and value selection clauses

Entity SQL supports two flavors of the SELECT clause. The first variant, row selection, is identified by the SELECT keyword and can be used to specify one or more values ​​to be projected. Since a row wrapper is implicitly extended by the returned values, the result of the query expression is always a multiset of rows.

An alias must be specified in each query expression in a row selection. If an alias is not specified, Entity SQL generates an alias using the alias generation rules.

The other variant of the SELECT clause, value selection, is specified by the SELECT VALUE keyword. It allows only one value to be specified and does not add a row wrapper.

A row selection can always be expressed using VALUE SELECT. This is illustrated in the following example.

The ALL and DISTINCT modifiers

Both variants of SELECT in Entity SQL allow an ALL modifier or a DISTINCT modifier to be specified. If the DISTINCT modifier is specified, duplicates are removed from the collection produced by the query expression (up to and including the SELECT clause). If the ALL modifier is specified, duplicates are not removed. This is the default setting.

Differences from Transact-SQL

Unlike Transact-SQL, Entity SQL does not support the use of the “*” argument in the SELECT clause. Instead, Entity SQL allows entire records to be projected out in queries by referring to the listing aliases of the FROM clause. This is illustrated in the following example.

The previous Transact-SQL query expression is expressed in Entity SQL as follows.


The following Entity SQL query uses the SELECT operator to specify the items to be returned by a query. This query is based on the AdventureWorks Sales model. To compile and run this query, do the following:

  1. Use the procedure in How to: Execute a Query that Returns StructuralType Results.

  2. Pass the following query as an argument to the method:

additional Information