使用FULL OUTER JOIN拼接多表數(shù)據(jù)
Jun 07, 2016 pm 05:21 PM所以這個(gè)Report直接使用INNER JOIN或者Left join/Right Join連接兩張表都得不到想要的數(shù)據(jù)。當(dāng)時(shí)Report的開發(fā)者的思路是先將符合
使用FULL OUTER JOIN拼接多表數(shù)據(jù)
[日期:2012-10-19] 來源:Linux社區(qū)? 作者:SmithLiu328 [字體:]
今天幫用戶修改一個(gè)報(bào)表,里邊設(shè)計(jì)到出庫(kù)和入庫(kù)的操作,要將每個(gè)產(chǎn)品每天的出入口信息列出來。
可能存在這樣的情況:
1.? 產(chǎn)品在出庫(kù)表中存在數(shù)據(jù)但是入庫(kù)表中沒有數(shù)據(jù)
2.? 產(chǎn)品入庫(kù)表中存在數(shù)據(jù)但是出庫(kù)表中沒有數(shù)據(jù)
所以這個(gè)Report直接使用INNER JOIN或者Left join/Right Join連接兩張表都得不到想要的數(shù)據(jù)。當(dāng)時(shí)Report的開發(fā)者的思路是先將符合條件的產(chǎn)品從出庫(kù)表和入庫(kù)表中找出來,然后使用LEFT JOIN連接入庫(kù)表和出庫(kù)表獲得最終數(shù)據(jù)。當(dāng)然這樣做沒有問題,但是不需要中間表,只需要借助FULL OUTER JOIN就可以獲得需要的數(shù)據(jù)。(FULL OUTER JOIN平時(shí)一般很少用到)
這里我們舉個(gè)例子:
QTYINT)
QTY
1,10)
2,20)
?
2,30)
3,40)
--希望得到的最終結(jié)果:
BON A.ID= B.ID
??
BON A.ID= B.ID
??
BON A.ID= B.ID
?
BON A.ID= B.ID
UNION
BON A.ID= B.ID

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Microsoft SQL Server is a relational database management system launched by Microsoft. It is a comprehensive database platform that uses integrated business intelligence (BI) tools to provide enterprise-level data management. It is easy to use, has good scalability, and has a high degree of integration with related software. High advantages. The SQL Server database engine provides more secure and reliable storage functions for relational data and structured data, allowing users to build and manage highly available and high-performance data applications for business.

With the popularity of the Internet, website and application development has become the main business of many companies and individuals. PHP and SQLServer database are two very important tools. PHP is a server-side scripting language that can be used to develop dynamic websites; SQL Server is a relational database management system developed by Microsoft and has a wide range of application scenarios. In this article, we will discuss the development of PHP and SQL Server, as well as their advantages, disadvantages and application methods. First, let's

Introduction to how to use PDO to connect to a Microsoft SQL Server database: PDO (PHPDataObjects) is a unified interface for accessing databases provided by PHP. It provides many advantages, such as implementing an abstraction layer of the database and making it easy to switch between different database types without modifying a large amount of code. This article will introduce how to use PDO to connect to a Microsoft SQL Server database and provide some related code examples. step

In web development, the combination of PHP and MySQL is very common. However, in some cases, we need to connect to other types of databases, such as SQL Server. In this article, we will cover five different ways to connect to SQL Server using PHP.

SQL Server vs. MySQL: Which database is more suitable for high availability architecture? In today's data-driven world, high availability is one of the necessities for building reliable and stable systems. As the core component of data storage and management, the database's high availability is crucial to the business operation of the enterprise. Among the many databases, SQLServer and MySQL are common choices. So in terms of high availability architecture, which database is more suitable? This article will compare the two and give some suggestions.

SQLServer or MySQL? The latest research reveals the best database selection. In recent years, with the rapid development of the Internet and big data, database selection has become an important issue faced by enterprises and developers. Among many databases, SQL Server and MySQL, as the two most common and widely used relational databases, are highly controversial. So, between SQLServer and MySQL, which one should you choose? The latest research sheds light on this problem for us. First, let

SQLServer and MySQL are currently two very popular relational database management systems (RDBMS). They are both powerful tools for storing and managing large-scale data. However, they have some differences in handling large-scale data. This article will compare SQL Server and MySQL, focusing on their suitability for large-scale data processing. First, let us understand the basic characteristics of SQLServer and MySQL. SQLServer is developed by Microsoft

With the widespread use of enterprise-level applications, SQL Server has also become one of the most widely used databases in enterprise-level applications. Moreover, with the popularity of Go language, more and more developers hope to use SQLServer in Go language. In this article, we will introduce how to use SQLServer in Go language, involving a complete guide to connecting, querying, reading and writing data, etc. Connect to SQLServer database Connect to SQLServer
