SQL statement related: It is difficult to detect during testing.
Source: Internet
Author: User
That is to say, if versionid on the left is null and only simple association is used, the row whose versionid is null cannot be found and must be connected through left or right connections. -- Create Table Table1, Table2: Create Table Table1 (ID int, name varchar (10) Create Table Table2 (ID int, score INT) insert into Table1 select 1, 'lil' insert into Table1 select 2, 'zhang 'insert into Table1 select 4, 'wang' insert into Table2 select 2,100 insert into Table2 Select Insert into Table2 select as table --------------------- ---------------------------- Table1 | Table2 | ------------------------------------------------- idname | idscore | 1lee | 190 | 2zhang | 2100 | 4wang | 370 | this very important string SQL = "select distinct projectid, projectname, P. versionid, D. versionname, isrecommend, industrytype, createdate, usecounter, creater, createdate, cast (P. remark as varchar (200) as remark from t_projectinfo P left join t_dataversion D on p. versionid = D. version Id {0} order by projectid DESC "; left join table B, based on table A, all data in Table A, and a combination of Table B. None of them are nulla table right join B table right join, which is based on table B, all data of Table B, some combinations of Table. Null left join: left join or left Outer Join (1) result set of left Outer Join includes all rows in the left table specified in the left outer clause, it is not just the rows matched by the join column. If a row in the left table does not match a row in the right table, all the selection list columns in the right table in the row of the associated result set are null ). (2) SQL statement SQL Code Select * From Table1 left join Table2 on table1.id = table2.id ------------- result --------------- idnameidscore -------------------------- 1lee1902zhang21004wangnullnull ------------------------------ Note: all clauses containing Table1 return the corresponding fields of Table2 according to the specified conditions, non-conforming values are displayed as null. 3. right join: Right join or right Outer Join (1) Right outer join is a reverse join of left Outer Join. All rows in the right table are returned. If a row in the right table does not match a row in the left table, a null value is returned for the left table. (2) SQL statement SQL code select * From Table1 right join Table2 on table1.id = table2.id select * From Table1 right join Table2 on table1.id = table2.id ----------- result ----------- idnameidscore too many else note: return the corresponding fields of Table 1 Based on the specified conditions for all clauses that contain table 2. If the fields do not meet the conditions, null is displayed. full external join: Full join or full outer join (1) full external join returns all rows in the left and right tables. If a row does not match a row in another table, the selection list column of the other table contains a null value. If there are matched rows between tables, the entire result set row contains the data value of the base table. (2) SQL statement SQL code select * From Table1 full join Table2 on table1.id = table2.id select * From Table1 full join Table2 on table1.id = table2.id ----------- result ----------- idnameidscore too many else note: returns the sum of left and right connections (see upper left and right connections). 2. inner connection. 1. concept: inner join is a join that uses a comparison operator to compare the values of the columns to be joined. 2. internal join: Join or inner join 3. SQL statement SQL code select * From Table1 join Table2 o N table1.id = table2.id select * From Table1 join Table2 on table1.id = table2.id ------------- result ------------- idnameidscore limit 1lee1902zhang2100 limit Note: only Table1 and Table2 columns meeting the condition are returned. equivalent SQL code -- A: select. *, B. * From Table1 A, Table2 B where. id = B. id -- B: Select * From Table1 cross join Table2 where table1.id = table2.id -- A: select. *, B. * From Tab Le1 A, Table2 B where. id = B. id -- B: Select * From Table1 cross join Table2 where table1.id = table2.id (Note: cross join can only use where, cannot use on) 3. Cross join (complete) 1. concept: A 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. (Table1 and Table2 cross join generate 3*3 = 9 records) 2. cross join: cross join (without the condition where ...) 3. SQL statement SQL code select * From Table1 cross join Table2 select * From Table1 cross join Table2 ------------- result ------------- idnameidscore invalid score -------------------------- Note: 3*3 = 9 records are returned, I .e., Cartesian Product
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service