- SQL - Discussion
- SQL - Useful Resources
- SQL - Useful Functions
- SQL - Quick Guide
- SQL - Questions and Answers
- SQL - Datatype Functions
- SQL - Conversion Functions
- SQL - JSON Functions
- SQL - Cursor Functions
- SQL - Logical Functions
- SQL - Statistical Functions
- SQL - Text & Image Functions
- SQL - Numeric Functions
- SQL - Aggregate Functions
- SQL - String Functions
- SQL - Date Functions
- SQL - Database Tuning
- SQL - IN vs EXISTS
- SQL - Group By vs Order By
- SQL - Common Table Expression
- SQL - Cursors
- SQL - Date & Time
- SQL - Auto Increment
- SQL - Using Sequences
- SQL - Handling Duplicates
- SQL - Sub Queries
- SQL - Transactions
- SQL - NULL Values
- SQL - Stored Procedures
- SQL - Default Constraint
- SQL - Check Constraint
- SQL - Null Functions
- SQL - Min & Max
- SQL - Hosting
- SQL - Injection
- SQL - Comments
- SQL - Wildcards
- SQL - Non-Clustered Index
- SQL - Clustered Index
- SQL - Unique Index
- SQL - Primary Key
- - 工会诉Join
- SQL - Inner Join
- SQL - Using Joins
- SQL - Aliases
- SQL - EXCEPT Operator
- SQL - INTERSECT Operator
- SQL - UNION vs UNION ALL
- SQL - UNION Operator
- SQL - BETWEEN Operator
- SQL - NOT NULL
- SQL - IS NOT NULL
- SQL - IS NULL
- SQL - NOT EQUAL
- SQL - NOT Operator
- SQL - CASE
- SQL - EXISTS Operator
- SQL - ANY, ALL Operators
- SQL - IN Operator
- SQL - LIKE Operator
- SQL - BOOLEAN (BIT) Operator
- SQL - AND & OR
- SQL - Having Clause
- SQL - Group By Clause
- SQL - Order By Clause
- SQL - Distinct Clause
- SQL - Top Clause
- SQL - Where Clause
- SQL - Rename Views
- SQL - Drop Views
- SQL - Update Views
- SQL - Create Views
- SQL - Sorting Results
- SQL - Delete Query
- SQL - Update Query
- SQL - Insert Into Select
- SQL - Select Into
- SQL - Select Query
- SQL - Insert Query
- SQL - Constraints
- SQL - Delete Table
- SQL - Drop Table
- SQL - Alter Tables
- SQL - Temporary Tables
- SQL - Clone Tables
- SQL - Truncate Table
- SQL - Rename Table
- SQL - Show Tables
- SQL - Create Table
- SQL - Backup Database
- SQL - Show Database
- SQL - Rename Database
- SQL - Select Database
- SQL - Drop Database
- SQL - Create Database
- SQL - Expressions
- SQL - Operators
- SQL - Data Types
- SQL - Syntax
- SQL - Databases
- SQL - RDBMS Concepts
- SQL - Overview
- SQL - Home
5. 图瓦卢
- 页: 1
- 页: 1
- 结构-创建指数
- 页: 1
- 页: 1
- 页: 1
- SQL - Foreign Key
- 文 件
- ∗ E/CN.6/2009/1。
- 页: 1
- 页: 1
- 文 件
- 页: 1
- 页: 1
- 文 件
- 页: 1
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SQL - Left Join
凭单从两个或两个以上表格中检索记录,这些表格依据的是它们之间的逻辑关系。 这一关系是以合并的条件确定的。
当我们加入两个基于条件、内心合力的表格时,提供这些交叉值,即满足合并条件的表格的记录。
What is Outer Join?
与加入外部机构不同的是,可能包含不满足合并条件的记录以及满足这些记录的记录。 加入外层空间有三种类型:
Left Outer Join
Right Outer Join
Full Outer Join
每当我们加入表格时,如果左表(或第一表)的记录比右表(或第二表)多,或反之亦然,外面就为没有同 counterparts的记录显示民族解放军的价值观(如果不满足合并条件)。
Left Join in SQL
离开Join或左边的Join将两个或两个以上表格合并在一起,第一个表格全部归还;但只有对应记录从相应的表格中检索。 如果在随后的表格中记录为零(0)的话,合并后仍会退回一行,但右表各栏中各有全国人民力量。
Syntax
下面是Joinkou的基本yn子——
SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name = table_name2.column_name
Example
为了更好地理解这一询问,让我们在现有数据库中建立一些表格,并试图利用Join或Pier Outer Join与他们一道。
我们已经建立了一个名为Customers的表格,其中载有客户的个人详情,包括他们的姓名、年龄、地址和薪金,使用以下询问。
CREATE TABLE CUSTOMERS ( ID INT NOT NULL, NAME VARCHAR (20) NOT NULL, AGE INT NOT NULL, ADDRESS CHAR (25), SALARY DECIMAL (18, 2), PRIMARY KEY (ID) );
现在,在表格中添加以下价值观:
INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (1, Ramesh , 32, Ahmedabad , 2000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (2, Khilan , 25, Delhi , 1500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (3, kaushik , 23, Kota , 2000.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (4, Chaitap , 25, Mumbai , 6500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (5, Hardik , 27, Bhopal , 8500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (6, Komal , 22, MP , 4500.00 ); INSERT INTO CUSTOMERS (ID,NAME,AGE,ADDRESS,SALARY) VALUES (7, Muffy , 24, Indore , 10000.00 );
该表将编成:
+----+----------+-----+-----------+----------+ | ID | NAME | AGE | ADDRESS | SALARY | +----+----------+-----+-----------+----------+ | 1 | Ramesh | 32 | Ahmedabad | 2000.00 | | 2 | Khilan | 25 | Delhi | 1500.00 | | 3 | Kaushik | 23 | Kota | 2000.00 | | 4 | Chaitap | 25 | Mumbai | 6500.00 | | 5 | Hardik | 27 | Bhopal | 8500.00 | | 6 | Komal | 22 | MP | 4500.00 | | 7 | Muffy | 24 | Indore | 10000.00 | +----+----------+-----+-----------+----------+
让我们制定另一份表格命令,载列所发布命令的细节和日期。
CREATE TABLE ORDERS ( OID INT NOT NULL, DATE VARCHAR (20) NOT NULL, CUSTOMER_ID INT NOT NULL, AMOUNT DECIMAL (18, 2), );
采用INSERT声明,在本表中插入以下数值:
INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (102, 2009-10-08 00:00:00 , 3, 3000.00); INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (100, 2009-10-08 00:00:00 , 3, 1500.00); INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (101, 2009-11-20 00:00:00 , 2, 1560.00); INSERT INTO ORDERS (OID, DATE, CUSTOMER_ID, AMOUNT) VALUES (103, 2008-05-20 00:00:00 , 4, 2060.00);
表格如下:
+-----+---------------------+-------------+---------+ | OID | DATE | CUSTOMER_ID | AMOUNT | +-----+---------------------+-------------+---------+ | 102 | 2009-10-08 00:00:00 | 3 | 3000.00 | | 100 | 2009-10-08 00:00:00 | 3 | 1500.00 | | 101 | 2009-11-20 00:00:00 | 2 | 1560.00 | | 103 | 2008-05-20 00:00:00 | 4 | 2060.00 | +-----+---------------------+-------------+---------+
我们利用left加入以下查询:,试图检索在规定日期发出订单但没有订单的客户的详细情况。 如果发现没有相应数据,下面的询问将使利比里亚全国人民力量在记录中返回。
SELECT ID, NAME, AMOUNT, DATE FROM CUSTOMERS LEFT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID;
Output
下表是:
+----+----------+---------------------+---------+ | ID | NAME | DATE | AMOUNT | +----+----------+---------------------+---------+ | 1 | Ramesh | NULL | NULL | | 2 | Khilan | 2009-11-20 00:00:00 | 1560.00 | | 3 | Kaushik | 2009-10-08 00:00:00 | 1500.00 | | 3 | Kaushik | 2009-10-08 00:00:00 | 3000.00 | | 4 | Chaitap | 2008-05-20 00:00:00 | 2060.00 | | 5 | Hardik | NULL | NULL | | 6 | Komal | NULL | NULL | | 7 | Muffy | NULL | NULL | +----+----------+---------------------+---------+
如上表所示,只有Khilan、Kaushik和Chaitap在订单表中的上述日期购买了这些记录;因此,这些记录是相应的。 客户表中的其他客户未在规定日期进行采购,因此这些记录作为NUL收回。
Joining Multiple Tables with Left Join
与Inner Join query相似,若留任也加入了多个表格,其中第一个表格全部交回,下个表格与第一张表格中的行文相匹配。 如果记录不匹配,则将归还联合国利比里亚特派团。
The syntax to participate multi table using Josignin is given below -
SELECT column1, column2, column3… FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name LEFT JOIN table3 ON table2.column_name = table3.column_name . . .
Example
为了用多种表格显示Join,让我们考虑以前制作的表格客户和订单。 除这些外,我们将努力利用以下询问创建“就业岗位”表:
CREATE TABLE EMPLOYEE ( EID INT NOT NULL, EMPLOYEE_NAME VARCHAR (30) NOT NULL, SALES_MADE DECIMAL (20) );
现在,我们可以利用INSERT声明,将价值观纳入这一空表:
INSERT INTO EMPLOYEE VALUES (102, SARIKA , 4500); INSERT INTO EMPLOYEE VALUES (100, ALEKHYA , 3623); INSERT INTO EMPLOYEE VALUES (101, REVATHI , 1291); INSERT INTO EMPLOYEE VALUES (103, VIVEK , 3426);
员工表包括组织中员工的详细信息和销售额。
+-----+---------------+------------+ | EID | EMPLOYEE_NAME | SALES_MADE | +-----+---------------+------------+ | 102 | SARIKA | 4500 | | 100 | ALEKHYA | 3623 | | 101 | REVATHI | 1291 | | 103 | VIVEK | 3426 | | 100 | ALEKHYA | 3456 | +-----+---------------+------------+
Left Join Query
让我们利用下面的左边共同点,努力加入这三个表格:
SELECT CUSTOMERS.ID, CUSTOMERS.NAME, ORDERS.DATE, EMPLOYEE.EMPLOYEE_NAME FROM CUSTOMERS LEFT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID LEFT JOIN EMPLOYEE ON ORDERS.OID = EMPLOYEE.EID;
通过这一询问,我们试图展示客户身份、客户名称、具体日期和出售客户的雇员姓名的记录。
Output
下表是:
+----+----------+---------------------+---------------+ | ID | NAME | DATE | EMPLOYEE_NAME | +----+----------+---------------------+---------------+ | 1 | Ramesh | NULL | NULL | | 2 | Khilan | 2009-11-20 00:00:00 | REVATHI | | 3 | Kaushik | 2009-10-08 00:00:00 | ALEKHYA | | 3 | Kaushik | 2009-10-08 00:00:00 | ALEKHYA | | 3 | Kaushik | 2009-10-08 00:00:00 | SARIKA | | 4 | Chaitap | 2008-05-20 00:00:00 | VIVEK | | 5 | Hardik | NULL | NULL | | 6 | Komal | NULL | NULL | | 7 | Muffy | NULL | NULL | +----+----------+---------------------+---------------+
如上表所示,客户Kaushik下达了三项命令,其中两项由雇员Alekhya出售,一项由Sarika出售。 Khilan和Chaitap分别发出订单,分别由Revathi和Vivek出售。 这些命令的日期也将显示。 如果在具体日期未下达命令,全国人民代表大会将予退回。
Left Join with WHERE Clause
除《政府公报》条款外,还可在《离开约恩》执行后获得的表格上适用《惠予公约》条款。 这样做将进一步过滤数据。
Syntax
The syntax of Coron Join when used with WHERE clauses is given below -
SELECT column_name(s) FROM table_name1 LEFT JOIN table_name2 ON table_name1.column_name = table_name2.column_name WHERE condition
Example
数据库综合表中的记录可使用WHERE条款进行过滤。 考虑前两个表格的客户和订单;利用《惠予公约》条款实行某些限制,试图利用左边的同 que。
SELECT ID, NAME, DATE, AMOUNT FROM CUSTOMERS LEFT JOIN ORDERS ON CUSTOMERS.ID = ORDERS.CUSTOMER_ID WHERE ORDERS.AMOUNT > 2000.00;
Output
适用留守条款后得出的表格中含有价值大于2000年的行文。
+----+----------+---------------------+---------+ | ID | NAME | DATE | AMOUNT | +----+----------+---------------------+---------+ | 3 | Kaushik | 2009-10-08 00:00:00 | 3000.00 | | 4 | Chaitap | 2008-05-20 00:00:00 | 2060.00 | +----+----------+---------------------+---------+Advertisements