SQL group queries and connection queries

Source: Internet
Author: User

Group queries
Select query information from table name
Where condition
Group By column (multiple, separated)
Order by Sort method
(Query information if the column name and aggregate function appear at the same time, either in an aggregate function or in a group query)

Having conditional grouping filter (usually with group by, position behind)

Where: A row that is used to filter the resulting rows from the operation specified by the FROM clause
GROUP BY: Used to group the WHERE clause output
Having: Used to filter rows from the results of a grouping

1. A group query is a classification of statistics and outputs for different groups in a table
2.having clauses can be filtered again on a group basis
3. Use the order in the SQL statement, Where-->group by-->having

Anatomy:
1.select Query What
2.from from where to query
3.where Column name criteria (fuzzy query, relational expression query)
4.grop by group Query
Aggregation function filtering after 5.haing grouping

Table Connection
Select column from table 1, table 2
Where Condition (table 1. primary key column = Table 2. Foreign key column)

Internal connection (inner join)
Select column from table 1 inner JOIN table 2
On conditions (table 1. primary key column = Table 2. Foreign key column)

As can also assign aliases to tables

Outer JOIN (two Outer connection main table position opposite)
Left OUTER JOIN
Select column
From Main Table
Left OUTER join from table
On (table 1. primary key column = Table 2. Foreign key column)

Right outer join
Select column
From table
Right outer join Main Table
On (table 1. primary key column = Table 2. Foreign key column)

The data in the primary table (left/right table) is matched from the data in the table
1. Match, return to result set
2. No match, null value returned to result set

SQL group queries and connection queries

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.