Learn about difference between inner join and outer join, we have the largest and most updated difference between inner join and outer join information on alibabacloud.com
desired results
First, remove the foreign key of the products data table. Otherwise, a new supplierid in the products data table does not have a record mapped to the suppliers data table, to understand the constraint of a data table, you can execute the SQL built-in sp_helpconstraint, which is executed in QA.
Sp_helpconstraint Products
Next, delete the foreign key fk_products_suppliers.
Alter table Products
Drop constraint fk_products_suppliers
A new record is added to the products table. The s
products data table does not have a record mapped to the suppliers data table, to understand the constraint of a data table, you can execute the SQL built-in sp_helpconstraint, which is executed in QA.
Sp_helpconstraint Products
Next, delete the foreign key fk_products_suppliers.
Alter table Products
Drop constraint fk_products_suppliers
A new record is added to the products table. The supplierid uses 50 because it is not mapped to the suppliers table.
Insert into products (productname, supplie
connection is to remove all data from the right table, regardless of whether the table on the left has matching data:Select S.name,m.mark from student s right join Mark M on S.id=m.studentidThe above statement takes all the data from the Mark score table, regardless of whether there is a data match in the student table, as shown in:Iv. fully connected-full join:Remove the data from the left and right two tables, whether or not they match:Select S.nam
Test table:EMP Table Sal TableLeft JOIN: Results All rows are displayed in the table, and the right table determines that the column is the same as the left.SELECT * FROM EMP left join SAL on EMP. ename = SAL. ename; Right join: Results All rows are displayed in the table on the left, the table on the right is consistent with the tableSelect * from EMP right
(primary table) and the SAL (schedule) information related to EMP.
Right connect [SQL] view plain copy
Select * from EMP right join SAL on EMP. ename = SAL.ename;
Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wants to close.
Internal connection [SQL] view plain copy
SELECT * FROM
information of the EMP (primary table) and the SAL (schedule) information related to EMP.
Right-connect the Select * from emp to ' join SAL on EMP '. ename = SAL.ename; Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wants to close.
Internal Connection
main table, So the result of the query is to display all the information of the EMP (main table) and the SAL (schedule) information related to the EMP.
Right connect [SQL] view plain copy
Select * from EMP right join SAL on EMP. ename = SAL.ename;
Right connection, table Sal is the primary table, so the query results show all the information of the salt (the primary table) and the EMP (schedule) and the information that Sal wa
Label:Simply and clearly, connect to the inner and outer links. Suppose there are two tables of A and B Internal connection: Inner JOIN indicates that the record of the AB table is displayed, excluding the condition of the AB table . There are three kinds of outer joins, tha
Label:Original: http://blog.csdn.net/shadowyelling/article/details/7684714Left Join: Returns all the information in the table on the right and the information related to the left table conditionRight Join: Returns all of the information in the table in the list and information about the right table condition in the left tableInner Join: Returns information common
to (=) operator in the connection condition to compare the column values in the connected column. However, it uses the selection list to indicate the columns included in the query result set, delete duplicate columns in the connection table.For example, the following uses equijoin to list authors and publishers in the same city in the authors and publishers tables: Select *From authors as a inner join pub
Resolution: inline, left outer, right outer, full join, Cross join difference bitsCN.com
Connections include: internal connection, external connection, and cross connection.I. inner connection-the most commonDefinition:Only the ro
of course join how to combine the data of different database, also depends on how you use it, there are four different ways of join, in this article we will introduce you Inner join and Outer join and its application.
In a formal
The meaning of join is like the English word "join", connecting two tables, roughly divided into inner connection, outer connection, right connection, left connection, natural connection. The description here is to throw out a rotten picture and insert the test data.First of all, the classification (
Code is as follows:
Copy code
SELECT * FROMInner join BON a. aID = B. bID
Equivalent to the following SQL statement:
The Code is as follows:
Copy code
SELECT *FROM a, BWHERE a. aID = B. bID
The result is as follows:AID aNum bID bName1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 2006032404
Result description:Obviously, only the records of A. aID = B. bID are di
Let's look at one of the simplest inner joins, inner the corresponding class information from the Join Class table when reading the student table:Static voidMain (string[] args) { using(varwriter =NewStreamWriter (Watchsqlpath,false, Encoding.UTF8)) { using(Dbappdatacontext db =NewDbappdatacontext ()) {db. Log=writer; //
} {1} {2}", item.ClassID, item.ClassName, item.Student.Name); } } } Console.ReadLine();}
During Outer join, the joined table must be into a new variable gc, and gc. DefaultIfEmpty () is used to represent the Outer join.
Additional notes related to linq to SQL:
1. Starting from CUD, how to insert
An inner join connects only matching rowsThe left OUTER join contains all rows from the table on the left (regardless of whether there are rows in the right table that match them), and all rows in the right tableA LEFT join B is equivalent to a left
* from a LEFT join B on aid= bid and aid>3, return If a select * from a LEFT join B on aid= bid where aid>3 Because a temporary table is generated when executing such a statement, the condition in the on in this temporary table is not necessarily true, because it is possible that the field value is null.When a temporary table is generated, it is filtered according to the Where condition, so the condi
are as follows:AID Anum BID bname1 a20050111 1 20060324012 a20050112 2 20060324023 a20050113 3 20060324034 a20050114 4 2006032404 Result Description:Obviously, only a.aid = B.bid records are shown here. This shows that inner join is not based on who, it only shows records that match the criteria.--------------------------------------------Note:The left JOIN oper
Result Description:Obviously, only a.aid = B.bid records are shown here. This shows that inner join is not based on who, it only shows records that match the criteria.--------------------------------------------Note:The left JOIN operation is used to combine records from the source table in any from clause. Use the left JOIN
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.