SQL Server Simple Statement consolidation

Source: Internet
Author: User
Tags rtrim

1. Go to heavy distinct , group by

Select distinct  from table name
Select  from Group  by Userid,username


2. Go to space replace LTrim RTrim

 replace  (Name, " , " ) 
Select LTrim ('  test  ')        -- remove left blank   Selectrtrim ('  test  ')        -- Remove the space   on the right Selectltrim(rtrim('  test  ')-- remove leading and  trailing spaces

3. Table Association statement where Condition Association, left/Right Association

-- more fields to display with select Select B.id,gid,gname,gstand,ginprice,goutprice,gbaseclass,b_date,b_operson,b_time -- from the Tbl_goods table and the Tbl_sellbill table, set an alias a for the Tbl_goods table, set an alias for the Tbl_sellbill table B  from tbl_goods A,tbl_sellbill b -- Two tables associated condition is A.id=b.gid where a.id=B.gid
Select *  fromTableA A Left  JoinTableB b ona.ID=b.idSelect *  fromTableA A Right JoinTableB b ona.ID=b.idSelect *  fromTableA AInner JoinTableB b ona.ID=b.id Left Join(left join) returns records that include all records in the left table and the equivalent of the junction fields in the right table Right Join(right Join) returns records that include all records in the right table and the equivalent of the junction fields in the left tableInner Join(equivalent connection) returns only rows that have the same join field in two tables

SQL Server Simple Statement consolidation

Related Article

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.