without the where ConditionA cross join without a WHERE clause will generate the Cartesian product of the table involved in the join. The number of rows in the first table multiplied by the number of rows in the second table is equal to the size of the Cartesian result set. (Table 1 and Table 2 generate 6*3 = 18 Records)Equivalent to select vm. id, vm. voteTitle, vt. ip from voteMaster as vm, voter as vt
Stu_detail--second row description table connection on student.s_id = stu_detail.s_id; --The third line describes the conditions of the connection, usually the ID is equal 2. Full-Outer connection A full outer join, also known as a full outer join, returns all the record data in two connections. In the student table and the Stu_detail table, use the full outer join
Reprint: http://blog.chinaunix.net/uid-27570589-id-3771152.html Today, when parsing an SQL statement, it is found that the left join is not the same as the execution plan produced by the where A=b (+), and the efficiency is not the same.What the hell is going on? I got an article on the Internet.(1.) Order of execution of SELECT statements Processing Order of the SELECT statementThe following steps show the
table has been generated. At this point there is no left join meaning (must return the record of the table on the right), the condition is not true all filter out.Suppose there are two tables:Table 1:TAB2
Id
Size
1
10
2
20
3
30
Table 2:TAB2
Size
Name
10
Aaa
20
Bbb
20
Ccc
things to do all kinds of optimization, have not been how to improve Later, for the second way, the physical table is treated like this: use Column2 and #t共同去过滤TableA, wait until an intermediate result set, and then go to drive the other table Generated graphical execution plan, estimated two screens are not displayed, through step by step observation, looked for a long time, only to find that this difference, Although the final result is the same, but the efficiency of the query is very large,
Label:The test case table is as follows: 1. Take the intersection of 2 member tables (A∩B) T-sql: Select Member1.name,member1.age from Member1 join Member2 on Member1.name=member2.name
SELECT * from Member1
intersect
select * FROM Member2
2. Take the ∪ of the 2 member tables (a-B) T-sql: SELECT * FROM Member1
Union
SELECT * FROM Member2
3. Take in A i
exist on the left table = left tableRight Join--show the right table all the records that exist = Right tableFull join outer Joins--Displays the number of record records that exist for a table in two tables >= any tableCross join crossover--each record for left table corresponds to the number of records per record in the right table = Left table * Right tableHer
Join clause
I don't know if you've found it. We can only do this from one table when we use the SELECT statement to retrieve it. What if you want to retrieve it from two or more tables? Fortunately we can use a very useful feature of SQL and relational database systems, that is, "Join". For the sake of simplicity, "Join
Prerequisites:
Assume there are two tables
Table1:
ID data
1
2 B
3 C
Table2:
ID data
1
2 B
4 d
Question:
1. If you want to find the same data in Table1 and Table2,
The SQL statement is: Select table1.id, table1.data, table2.id, table2.dataFrom Table1 inner join Table2 on (table1.data = table2.data) and (table1.id = table2.id );
The query result is:
Table1_id
Tabledomaindata
T
----------------------INNER JOIN---------------------------1. Three-table joint query select Xx,xx from a, B, C Cartesian product, equivalent to cross join 2. Cross join--lists all combinations on both sides, also called Descartes set A.rows * b.rowsselect *from Sales S Cross join Customers C 3. INNER
SQL right join keyword
The right join keyword returns all rows from the right table (table_name2), even if no matching row exists in the left table (table_name1. Right join keyword syntax
Select column_name (s) from table_name1right join table_name2 on table_name1.column_n
SQL Full JOIN keywordThe full JOIN keyword returns a row whenever there is a match in one of the tables.Full JOIN keyword syntaxSELECT column_name (s) from Table_name1full JOIN table_name2 on Table_name1.column_name=table_name2.column_nameNote: In some databases, full
SELECT statement: SELECT Persons.lastname, Persons.firstname, Orders.orderno from
Persons right
JOIN Orders on
persons.id_p =orders.id_p
ORDER by Persons.lastname
Result set:
LastName
FirstName
OrderNo
Adams
John
22456
Adams
John
24562
Carter
Thomas
77895
Carter
Thomas
44678
34764
The r
Label:Joins are not used when joined, other types of connections must be used.such as SELECT * from TABLEA INNER JOIN TABLEB on A.id=b.idIt can be written like this:SELECT * from Tablea,tableb WHERE a.id=b.idJoins are available in the following categories:INNER (internal connection)Specifies that each pair of matching rows is returned. Discards rows that do not match in two tables. If no join type is specif
As seen from many web pages, SQL Server has three join algorithms, nested loop join, merge join, and hash join. The most common of these is the nested loop join.In many articles that introduce nested loop join, it is mentioned tha
Drawing Interpreting SQL Join statementsI think Ligaya Turmelle's post on SQL Union (join) statements is a good piece of material for a novice developer. SQL Union statements appear to be based on collections, and it is natural to use the Wayne diagram to explain how I see i
Label:Ext.: http://blog.jobbole.com/40443/ This article by Bole Online-Qi Feng Yu Gu translation. without permission, no reprint!English Source: Jeff Atwood. Welcome to join the translation team. I think Ligaya Turmelle's post on SQL Union (join) statements is a good piece of material for a novice developer. SQL Union
Label:In the company to help new people check the problem, found that someone wrote SQL is not accustomed to using the join statement, look at the writing is very simple, but the amount of data more execution will be very slow. Looking closely, you will often write multiple tables in the from in a SQL query, for example: Select A.a1,a.a2,b.b1,b.b2 from A, a where
SQL join on joint query instance
SQL join-use joinIn addition to the above method, we can also use the keyword join to obtain data from two tables.
If we want to list the orders of all users, we can use the following select statement:
Select persons. lastname, persons.
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.