SQL solves the uniqueness of distinct and groupby statements

Source: Internet
Author: User

Test environment: mssql2005

Sometimes we need to select a column as a unique value. The methods include distinct and groupby. However, if we select multiple columns, the results may not be unique if it is a non-aggregate function.

 

Therefore, using virtual columns makes sense.

 

Examples of online borrowing:

How to select a virtual column and fill it with null? Suppose there is only one column in the table, tselect distinct T, 0 as C1, 'abc' as C2, ''as C3 from table the result is t C1 C2 C31 0 ABC 2 0 abc3 0 ABC so that we can obtain the unique value of T, and also obtain the column C1, C2, c3 in disguise to solve some Application Problems of distinct and groupby.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.