, in a table in the aid and B table Bnameid is two connection fields.
Figure 3 below illustrates the relationship between all the recordsets of a connection:
Figure 3: Connection diagram
Now we're going to talk about one by one of our internal and external connections.
1. Inner connection: Use the inner connection to get the record of the public part of the two tables, that is, the recordset C of Figure
ArticleDirectory
1. Example of replacing inner join with exists:
When using exists, if you can use it correctly, it may increase the query speed:
1. Replace inner join with exists
2. Replace in with exists
1. Example of replacing inner
1. The connection statement used in the WHERE clause, in the database language, is called an implicit connection. INNER JOIN ... An ON clause produces a connection called a dominant connection. (Other join parameters are also dominant connections) the connection between the WHERE and the inner
You can implement an inner join by using the INNER JOIN clause, as long as there is a matching value between the associated fields of the two tables corresponding to the two persisted classes, the inner joins will combine the joins in the two tables. The
, the data consistency is well guaranteed.
Why use Joins?As just explained, breaking data into multiple tables enables more efficient storage (efficient storage), easier manipulation (easy to operate), and Greater scalability (very high scalability). But these benefits come and a price.If data is stored in multiple tables, how can I retrieve that data with a single SELECT statement?The answer is to use a join.It is important to understand that a join
SQL INNER JOIN keyword usage tutorial
When the keyword of inner join is returned, at least one row in the competition is returned.
SQL Syntax of INNER JOIN
SELECT column_name(s)FROM table_name1INNER
Business background:ERP system has a program ZPPR0002, each time the MES system release production orders in the ERP.The production order data contains the BOM component, which is the 1500 item information that makes up the finished vehicle.Symptoms:Recently, business staff feedback production order transmission slow, an order to 2 minutes, 80 orders a day, to finish the transmission will be a few hours.Reason:With SE30 debugging, it is found that the program spends 90% of its time on a
the same as that shown above!4: inner join or join; It is the record that the returned field ID exists in both the table votemaster and voter. 5: cross join (full join) cross join without the where Condition A cross
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 example you can use a LEFT
-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
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-many relationship. Multiple conditions need
SQL INNER JOIN keyword usage tutorial
When the keyword of inner join is returned, at least one row in the competition is returned.SQL Syntax of INNER JOIN
SELECT column_name(s)FROM table_name1INNER
Reference Problem description:
There are three tables:
Student Information table S (sno, sname)
Course information table C (cno, cname, cteacher)
Student-course relationship table SC (sno, cno, scroce)
Question 1: find out the names of all students who have not taken the course taught by Mr. Li Ming.
Question 2: The name of two or more failed students is displayed.
Question 3: find out the names of students who have selected both course "1" and course "2 ".
Main test: group by,
multiplied by the number of rows in the second table.
Do not forget the WHERE clause, and make sure that all connections contain a WHERE clause, otherwise MARIADB will return more data than you need. Similarly, make sure that the WHERE clause is used correctly, and that the wrong filter condition will cause MARIADB to return incorrect data.
Cross-Joins This is the connection type of the Cartesian product.
SELECT Vend_name, Prod_name, Prod_price from Vendors, products ORDER
Prerequisites:
Assume there are two tables
Table1:
ID data
1
2 B
3 C
Table2:
ID data
1
2 B
4 d
Question:
1. If you want to find the same data in Table1 and Table2,
The SQL statement is: Select table1.id, table1.data, table2.id, table2.dataFrom Table1 inner join Table2 on (table1.data = table2.data) and (table1.id = table2.id );
The query result is:
Table1_id
Tabledomaindata
T
Tags: img Connection Inner Example process statistics COM ALT operatorIn a comma-stitched string, the element string passed to the in clause includes more than 1400 elements The two approaches were and E.sspfcityid in (SELECTCAST (value as INT)From String_split (' 110000,310000,120000,210100,210200,210400,210800,211200,350100,350500,350200,350800,350700,350900,441200,441300,440500,44 5100,450100,451000,450800,450300,451100,450200,450900,450500,450400,
In the following example, 3 Join methods are implemented to connect two DataTable, equivalent to the SQL inner join method, and return all columns of the DataTable.If the DataColumn in the two DataTable is duplicated, the second is set to Columnname+ "_second", and the following code is in the hope of helping.Using System;Using System.Data;
Namespace WindowsAppli
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 inner
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.