Today, I helped developers optimize SQL and found a problem that I didn't care much about before.
SELECTbond.store_noFROMbill_order_num_dtlbondWHEREEXISTS(select1frommeetorder_staff_dtlb,meetorder_staffawhereb.operate_area=bond.store_noanda.seq_no=b.seq_noanda.user_code=‘lym‘);
The query requires 2 s, bill_order_num_dtl has more than 2 W data records, and meetorder_staff_dtl has about 50 records. After replacing exists with
is how to create different views for different siege lions. The following uses MYSQL as an example to illustrate how to use inner join and nested queries to implement multi-table queries. In fact, all databases are the same, and SQL statements are common.
I. Basic Objectives
It is known that in the test database, the
In-depth introduction to SQL left join, right join, and full join
We introduced table join, more specifically inner joins internal join. Only two records matching each other are sel
For SQL joins, learning may be a bit confusing. We know that the join syntax for SQL has a lot of inner, outer, left, and sometimes it's not very clear what the result set looks like for a select. There is an article on Coding horror (it is not clear why Coding horror was also the wall) through the Venturi diagram Venn
Oracle connections are divided into the following types:Inner join ).Outer Join: Full join, left join, and right join ).Cross join ).
The outer join is different from the
regarded as the right table, and B can be regarded as left table.In other words, the records of the left table (A) will all be represented, and the right table (B) will only display records that match the search criteria (in the example: A.aid = b.bid).The low-record of table B is null.--------------------------------------------2.right JoinThe SQL statements are as follows:SELECT * FROM ARight
When querying for data. It's strange to write a piece of SQL. No duplicate data occurs when you query data from the first 5 tables
There is a lot of duplicate data until the sixth table is associated (t_im_inventorybalance ). For a time it was depressing. Then consult the implementation personnel to know.
The original t_im_inventorybalance itself has multiple duplicate data, which means that when Material.fid = Ib.fmaterialid Association
It's a one-to
The main spirit of Inner Join is exclusive, call it exclusivity! That is, the data that does not match the Join rules will be excluded, such as the Supplier Code (SUPPLIERID) of a product that does not appear in the Suppliers table, and this record will be ruled out.Outer Join:Select The syntax of Outer can be omitted, for ex
SQL Join may be messy during learning. We know that the Join Syntax of SQL has many inner, outer, and left clauses. Sometimes, it is not clear about the result set of Select statements. In an article on Coding Horror (it is not clear why Coding Horror is also walled), Venn d
-free Empress','Taoism'),
*('Heavenly Queen','Taoism')
$
Panax Notoginseng--insert these lines into this location - Insert into location theValues'Buddhist','India'),
+('Taoism','China'),
A('Christ','Western'),
the('Confucian','China')
+
---inner JOIN inline, link the teacher table to the location table $--teacher is the main table, location is attached table, with teacher $
---only the matching
The Inner join is where the two tables do the same part of the record to produce a recordset,
Union is the resulting two recordset (field to be the same) and together to become a new recordset
Select a.field1,b.field2 from Table1 A inner join Table2 B on A.field2=b.field2 where ....
Select Field1 from Table1 Union se
JOIN CUSTOMERS C on c.id=o.customer_id; The query results for Statement 9 and statement 10 are the same, as follows:
Four, Federated joins (union join): This is a rare way to connect. Oracle, MySQL is not supported, the role is to find all the differences between the outer and inner joins all the rows. This is more commonly used in the data analysis of e
calculation, and give him a condition.Statistics-Name | Work | Work number | List of personnel. Name=============================================Zhang San | Write a Report | A520024 | TomCan it be the same, so that the query efficiency is slower than the number of records * record several times?The connection name query will then become:Statistics-Name | Work | Work number | List of personnel. Name=============================================Zhang San | Write a Report | A520024 | Tom 1*1 matche
Below ABAP Syntax is ABAP Inner Join example.
Start-of-selection.
* Assumption:all quantities is in sales units. Since quantities
* be summed to the material group level, it's assumed that all
* Materials within a material group has the same sales unit of
* measure.
Select A~kunag A~vbeln a~fkdat a~bukrs A~vbtyp
B~MATKL b~matnr b~arktx b~fkimg b~kzwi2 B~WAVWR
C~
Tags: mysq target ima STR Force Avoid association table WWW StatusProblemThe "show full processlist" statement makes it easy to find the problem SQL, as follows: SELECT post.* from
post
INNER JOIN post_tag on post.id = post_tag.post_id
WHERE post.status = 1 and post_tag.t ag_id = 123
ORDER by post.created DESC
LIMIT 100 Note: Because post and tag are many-to-many
Associations are often used in SQL, and when associated, they are restricted by where and on, where it is filtered at the time of the association, where it is filtered in the associated result set, but the use of inner The result of the join is the same as when the constraint is placed behind on and behind the Where.650) this.width=650; "style=" Float:none; "titl
Label:This article is about four kinds of connections in SQL-left outer connection, right outer connection, inner connection, full connection is introduced in detail, need friend reference
1. Inner Connection(A typical join operation, using a comparison operator like = or Inner
This article is about four kinds of connections in SQL-left outer connection, right outer connection, inner connection, full connection is introduced in detail, need friend reference1. Inner Connection(A typical join operation, using a comparison operator like = or Inner joi
Tags: track log technology class strong record manage base Select deep understanding of SQL four connections-left outer connection, right outer connection, inner connection, full connection 2016-06-06 11:27 263 people read Comments (0) favorite reports Classification:Database (6) 1. Inner Connection(A typical join o
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.