Connection query, structure, loop statement

Source: Internet
Author: User

1 Connection query: You can implement multiple table queries by using the Join operator.
1.1 Join on
Select Name,mark from student join Mark on Student.id=mark.studentid
Left JOIN Connect-left Join
Select Name,mark from student left join Mark on Student.id=mark.studentid
Right Connect-right Join
Select Name,mark from student right join Mark on Student.id=mark.studentid
Fully connected-full Join
Select Name,mark from student full join mark on Student.id=mark.studentid
1.2 UNION
Operator is used to combine the result set of two or more SELECT statements.
The SELECT statement inside the UNION must have the same number of columns.
The column must also have a similar data type. Also, the order of the columns in each SELECT statement must be the same.
SELECT column_name (s) from table_name1
UNION
SELECT column_name (s) from table_name2


In SQL language, variables are divided into local variables and global variables, and global variables are called system variables.
2 Local Variables
Declaration: Declare @< variable name > < variable type >
Assignment: Set @< variable name >= expression
You need to print a single quotation mark in a printed string: Double-two single quotes.

3 logical operators
All returns True if a set of comparisons is true.
and returns True if two Boolean expressions are true.
Any if any of the comparisons in a group is true, it returns true.
>between returns True if the operand is within a range.
exists returns TRUE if the subquery contains some rows.
In if the operand equals one in the expression list, true is returned.
Like if the operand matches a pattern, it returns true.
Not negate the value of any other Boolean operator.
Or if one of the two Boolean expressions is true, returns True.
Some returns true if, in a set of comparisons, some are true.

4 If...else ... Statement
DECLARE @name varchar (20)
Set @name = ' ASDFGHJKL '
If LEN (@name) <5
Begin
Print @name
End
Else
Print substring (@name, 1,4)


5 Case ... when ...
Select mm =
Case substring (cname,1,1)
When ' lead ' then ' a '
When ' Ben ' then ' B '
When ' white ' then ' C '
When ' 4 ' then ' d '
When ' 5 ' then ' e '
End
From Cang


6 While statement
DECLARE @cc varchar (10)
Set @cc = ' 123 '
While LEN (@cc) <6
Begin
Print @cc
Set @[email protected]+ ' 1 '
End
Select @cc

Connection query, structure, loop statement

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.