Joins with multiple table operations

Source: Internet
Author: User
Tags joins
1 function of as

As can fill in the new table with the query result of select

CREATE TABLE profession
(id int (one) NOT NULL Auto_increment primary key,
  profession varchar) as
sel ECT profession from the My_contacts group by the profession order by
profession;
alias for 2 columns

The column name changes the column name in the query result, but does not change the name of the source column. Aliases are only temporary. 3 alias of the table

Same as the alias of the column, as can omit

Select Profession (AS) mc_prof from 
my_contacts (AS) MC
Group BY profession Order by
profession;
4 Mating 1 Cross joins

Cross joins (cross join), also called Cartesian product, cross product, return the result of each row of two tables

Select T.toy,b.boy from
toys as T
Cross join
boys as B;
/*cross join can be omitted */
2 Inner joins

Cross joins are one of the inner joins. An inner join is a cross connection that removes some result data rows from a condition in the query.

Select Somecolumns from
table1 
inner join
table2 on
somecondition;
/*on can be changed to where*/

According to the different conditions, they can be divided into equal joins, unequal joins and natural joins.

/* Equal join *
/select T.toy,b.boy from
toys as T
inner join
boys as B on
b.toy_id=t.toy_id;

The conditions for unequal joins are "<>"
A natural join is an inner join that does not use the "on" clause. It is only useful if the joined columns have the same names in both tables.

Select T.toy,b.boy from
toys as T
Natural join
boys as B;

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.