For example A1 table 100W row A2 table 50W rowSelect A.* from A1 a where a.column1 in (select B.column1 from A2 b where b.column2= ' xxx ');Select A.* from A1 a where exists (select ' x ' from A2 b where b.column2=xxx and a.column1=b.column1);Select a.* from A1 a,a2 b where b.column2= ' xxx ' and a.column1=b.column1In cases where the result set (for example, only dozens of) of (select B.column from A2 b w
publisher equals book. publisher into publisherbooks select new {publisher = publisher. name, books = publisherbooks}; gridviewgroupjoin. databind ();
AboveCodeIs the so-called "group connection ". It groups the books of each publishing house into publisherbooks and binds them together. This code is consistent with the running result of the following code.
VaR x = from book in sampledata. Books Group book by book. Publisher into bookpublishers select new {publisher = bookpublishers. Key. Na
. Internal connection, usually use the most, the simplest equals number connection example: There are two tables, assuming that A and B are many-to-one relationship a LEFT join B the number of records connected to a table with the number of recordsA Right JoinThe number of records connected to B is equal to the number of records connected in A and B plus the number of records on the B no matchThis way, you
Label:Using EF's own small functions need to encounter inner join and group by combination of use and anonymous type of processing, search a lot, basically can not meet their own needs, so summed up also realized on their own write out, has been prepared to view and partner query Reference (General statement query does not say, the network search a lot) Statement query background (or not directly look at th
right connections, if the two sides can not match the conditions, then do not take out. 7.MySQL does not support external connections , and, accordingly, MySQL can use Union (union query) to isolate the left and right connections. The union query filters for duplicate rows, and union all does not filter for duplicate rows . union query, the number of SQL columns between the Union must be equal, the column name is the first
the right table in the row of the associated result set are null.
2. left join/right join/inner join Operation demonstration
Table A records the following:AID aNum1 a200501112 a200501123 a200501134 a200501145 a20050115
Table B records the following:BID bName1 20060324012 20060324023 20060324034 20060324048 2006032408
list columns in the right table in the row of the associated result set are null.
2. Left join/right join/inner Join Operation demonstration
Table A records the following:Aid anum1 a200501112 a200501123 a200501134 a200501145 a20050115
Table B records the following:Bid bname1 20060324012 20060324023 20060324034 20
Table A records the following:
Aid anum
1 a20050111
2 a20050112
3 a20050113
4 a20050114
5 a20050115
Table B records the following:
Bid bname
1 2006032401
2 2006032402
3 2006032403
4 2006032404
8 2006032408
The experiment is as follows:
1. Left join
The SQL statement is as follows:
Select * from
Left join B
On a. Aid = B. Bid
The result is as follows:
Aid anum b
Various joins in MySQL
1. Cartesian Product (cross join)
In MySQL, you can think of cross join or omit cross as join, or use ','
For example
Select * From Table1 cross join Table2
Select * From Table1 join Table2
Select * From Ta
S.sno, Sname, S. Dname, S.cno, MARK, TnameFrom STUDENT as SINNER JOIN TEACHER as TOn S. dnameand S. CNO =t. CNOORDER BY Sname
The results of the operation are shown in Figure 9.14.
Figure 9.14 Query results with unequal connections
Describes that by default, a DBMS executes a multiple-table query by pressing INNER JOIN
field name in the SELECT statement. In this example, categories. categoryid.
You can also link Multiple on clauses in a join statement. Use the following syntax:
Select fieldsFrom Table1 inner join Table2On table1.field1 compopr table2.field1 andOn table1.field2 compopr table2.field2) orOn table1.field3 compopr tab
field name in the SELECT statement. In this example, categories. categoryid.
You can also link Multiple on clauses in a join statement. Use the following syntax:
Select fieldsFrom Table1 inner join Table2On table1.field1 compopr table2.field1 andOn table1.field2 compopr table2.field2) orOn table1.field3 compopr tab
a cross join on the College and Apply tables and generate a Cartesian product of the number of rows in the Data behavior College and Apply tables, that is, 5*20 = 100.
Cross apply
Cross apply is provided in SQL Server 2005 so that the table can be joined with the results of the table-valued functions TVF's function. For example, if we want to query the result
a20050114 4 20060324045 a20050115 NULL NULL(The number of rows affected is 5 rows)
Results show:The left join is based on the records of a table, and a can be viewed as the left-hand table, B can be viewed as the right table, and left table.In other words, the records in the left table (A) will all be represented, and the right table (B) will only display records that match the search criteria (in the example
a20050115 NULL(The number of affected rows is 5)
Result description:Left join is based on the records of table A. A can be seen as the left table, B can be seen as the right table, and left join is based on the left table.In other words, the records in the left table (A) are all expressed, while the right table (B) only displays records that meet the search criteria (in this
table, and a can be viewed as the left-hand table, B can be viewed as the right table, and left table.In other words, the records in the left table (A) will all be represented, and the right table (B) will only display records that match the search criteria (in the example: A.aid = b.bid).b tables where the records are insufficient are null.
2.right join (right join
Inner join
There are two tables A and B.
The structure of Table A is as follows:
Aid: int; identifies the seed, primary key, and auto-increment ID
Aname: varchar
The data, that is, the records from select * From A, are shown in 1:
Figure 1: data in Table
Table B has the following structure:
Bid: int; identifies the seed, primary key, and auto-increment ID
Bnameid: int
Data, that
Take a look at the results of the left join and the right join with the Inner join and the full join to manipulate the table.
Create a new two table in the database and insert the data you want to test.
New table:[SQL
First, take a look at some of the simplest examples.
Example
Table AAid Adate1 A12 A23 A3
TableB
Bid Bdate1 B12 B24 B4Two table a,b connected, to remove fields with the same IDSELECT * from a INNER join B on a.aid = B.bid This is the only matching data to be fetched.At this point, the removal is:1 A1 B12 A2 B2
So the left
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.