Wiki

Scale Your Enterprise

User Tools

Site Tools


bw:sql_server_tips

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
bw:sql_server_tips [2019/05/01 12:27]
runger
bw:sql_server_tips [2019/06/04 15:18] (current)
Line 71: Line 71:
 as datetime) as [CombinedDateTime] as datetime) as [CombinedDateTime]
 </code> </code>
 +
 +===== Use DISTINCT in a SQL Select Statement =====
 +If the DISTINCT operator is needed, it must be done within a sub-query.  For example, assume you have 12 records that have three distinct values of "Name" You want to display only the three unique names.  If you use the following statement, Versago will reject it.
 +
 +<code sql>
 +SELECT DISTINCT
 +t0.Name
 +from TableName t0
 +</code>
 +
 +However, if this statement is used as a sub-query, it can be used in Versago.  The statement will look like this.
 +
 +<code sql>
 +SELECT a0.* from
 +(
 +SELECT DISTINCT
 +t0.Name
 +from TableName t0
 +) a0
 +</code>
 +
 +In this case, "a0" is an alias for the results of the SELECT DISTINCT statement.  There is no significance to the alias name "a0" It is simply used here for convenience.
bw/sql_server_tips.1556728075.txt.gz · Last modified: 2019/05/01 12:27 by runger