Alibabacloud.com offers a wide variety of articles about select from two tables sql without join, easily find your select from two tables sql without join information here online.
SQL table join query (inner join, full join, left join, right join)
Prerequisites: Assume that there are two tables, one is the student table and the other is the student renewal 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.studentid The 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
SQL left Outer Join, right Outer Join, full join, internal joinThe connection conditions can be specified in the from or where clause. We recommend that you specify the connection conditions in the from clause. The where and having clauses can also contain search conditions to further filter the rows selected by the co
The following is a 137-row SQL statement. If you understand this, I want to know about left join and inner join. (My personal opinion only)
The following is a piece of code:
Select num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, area. areacode, area. areaname, num11
From(
Tags: description database table selection No related detailed associated demo postFirst, let's look at some of the simplest examples. Example Table AAid Adate1 A12 A23 A3 TableB Bid Bdate1 B12 B24 B4Two tables A, B connected, to remove fields with the same IDSELECT * from a INNER join B on a.aid = B.bid This is only the matching data is taken out.At this point, the removal is:1 A1 B12 A2 B2Then the left
elements are in a, not in B, and vice versa.Set Set "B" AA BB -- ------ -------- 1 3 24 3 5 4 6Left OUTER JOINNow execute the following SQL statement (left connection, OUTER join):SELECT * from Left OUTER JOIN on = BbYou will get the following result (blank element representation NULL ):AA BB -- ------ -------- 1
Cross Jointable2Select * fromTable1,table2--The following three statements have the same effectSelect * fromTable1 A,table2 bwhereb.ID=a.idSelect * fromTable1 A Cross JoinTable2 bwhereb.ID=a.idSelect * fromTable1 AInner JoinTable2 b onb.ID=a.ID2 Cross Apply,outer apply(Cross Apply,outer apply is new in SQL Server 2005)There is a cross join in SQL Server 2000
Label:--Build Table Table1,table2:CREATE TABLE table1 (ID int,name varchar (10))CREATE TABLE table2 (ID int,score int)Insert INTO table1 Select 1,leeInsert INTO table1 Select 2,zhangInsert INTO table1 Select 4,wangInsert INTO table2 Select 1,90Insert INTO table2 Select 2,100
. au_lname, P. pub_nameFrom authors as a inner join publishers as POn a. City = P. CityAnd a. State = P. StateOrder by A. au_lname ASC, A. au_fname ASC
Tables or views in the from clause can be specified in any order through internal connections or complete external connections. However, when you connect to a specified table or view from the left or right, the order of
Label: INNER JOIN (equivalent join) returns only rows that have the same join field in two tables Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right table Right
Label: Inner JOIN (equivalent connection) returns only rows that have the same join field in two tables Left join returns records containing all the records in the left table and the equivalent of the junction fields in the right table Right join returns records that contain
Left join returns records that include all records in the left table and join fields in the right table.Right join returns records that include all records in the right table and the joined fields in the left table.Inner join (equivalent join) returns only rows with equal
I. Concepts
1. Cross join)Without the WHERE clause, it returns the Cartesian product of the two joined tables, and the number of rows returned is equal to the product of the number of rows in the two tables.For example:A: select a. *, B. * From Table1 A, Table2 B where a. ID = B. IDB: Select * From Table1 a cross
some elements are in a, not in B, and vice versa.
Set " A" set "B"
AA BB
-------- --------
Item 1 Item 3
Item 2 Item 4
Item 3 Item 5
Item 4 Item 6
Left OUTER JOINNow execute the following SQL statement (left connection, OUTER join):
SELECT * from A left OUTER
(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 Sa
Label:Transferred from: http://blog.csdn.net/jz20110918/article/details/41806611 Let's say we have two tables. Table A is the sheet on the left. Table B is the list on the right. Each of them has four records, of which two records name is the same, as follows: Let's look at the different joins
Table A
Id
Name
1
Pirate
2
Monkey
3
Ninja
In the relational database management system, the relationship between data does not have to be determined when a table is created, and all information about an object is often stored in a table. When retrieving data, you can use the join operation to query information about different entities in multiple tables. Connection operations bring great flexibility to users. They can add new data types at any time
Connection property. If the value is mapped to I by a hash function, then the tuple of relation s must be in H (RI), and the tuple of the relationship s must be in H (SI). Therefore, the tuples in H (RI) need to be compared with the tuples in H (SI) and not necessarily with any other partitions of S. It is obvious that this algorithm is much less expensive than the above algorithm. as two tables are partitioned, the benefit is that you can use para
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.
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.