--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------
Inner JOIN and join is a meaning:
"Persons" table:
id_p |
LastName |
FirstName |
Address |
| City
1 |
Adams |
John |
Oxford Street |
London |
2 |
Bush |
George |
Fifth Avenue |
New York |
3 |
Carter |
Thomas |
Changan Street |
Beijing |
"Orders" table:
Id_o |
OrderNo |
id_p |
1 |
77895 |
3 |
2 |
44678 |
3 |
3 |
22456 |
1 |
4 |
24562 |
1 |
5 |
34764 |
65 |
Join-----> finds the primary key for the person in the order table, and when a join is made, the data row is returned whenever there is a match in the Orders table.
The LEFT JOIN----the >LEFT join keyword returns all rows from the table (Persons), even if there are no matching rows in the right table (Orders). The difference with join is that
In addition to returning data for join (as long as there is a match), return the data for the left table that does not match.
The RIGHT join----the >right join keyword returns all rows from that table (Orders), even if there are no matching rows in the left table (Persons). The difference with join is that
In addition to returning data for join (as long as there is a match), return the data for the right table that does not match.
The full JOIN keyword returns all rows from the left table (Persons) and the right table (Orders). If the rows in "Persons" do not match in the table "Orders",
Or if the rows in Orders do not have a match in the table "Persons", these lines are also listed. The difference with join is that
In addition to returning data for join, return (the left table does not match the data + the right table does not match the data)
You can see the relationship of the number of bars (left join+ right join-join) = Full join;
--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------
The UNION operator is used to combine the result set of two or more SELECT statements. Use remember: Merge result sets
Select E_name from Employees_china UNION
select E_name from Employees_usa
Note that the two-sheet column should be consistent,
The Union takes non-repeating data, and the union all takes duplicate data.
--------------------------------------------------------------------------------------------------------------- ------------------------------------------------------
Select INTO is used to create a backup of the data table ...----------------------------------> test found this statement will be error, do not know the correct how to write?
SELECT *into new_table_name [in Externaldatabase] from Old_tablename
--------------------------------------------------------------------------------------------------------------- ---------------------------------
Like operator
Example: SELECT * from Person p where p.name like '%youpeng% ';------------------->%
SELECT * from Man p where p.nake like ' _youpeng ';-----------------------> First character any match, followed by Youpeng
SELECT * from Man p where p.name like ' [a,b,s]% ';------------------------> First character must be a or B or S, followed by an arbitrary match.
SELECT * from Man p where p.name like ' [! a,b,s]% ';------------------------> The first character cannot be a or B or S, followed by an arbitrary match.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------
Between operator
operator between ... and selects a range of data between two values. These values can be numeric, text, or date.
Note: Different databases treat between differently, especially with respect to boundary values.
--------------------------------------------------------------------------------------------------------------- -------------------------------------------------------
SQL Build Table statement
Example Sql:create TABLE Persons
(id_p int, LastName varchar (255), FirstName varchar (255), Address varchar (255), City varchar (255))
SQL Small Summary