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