Tags: SQL statementsProject requirements change, before writing a query SQL, need to modify, nausea for a long while did not change well, finally want to go, spell to spell (splicing SQL), the original directly to the inner join changed to the left join on OK.After writing that feeling Ah! Really for the fountainhead come ah, what the best programming habit is to
Four sheets contract, customer, Customer3, Customer4:
This is a more familiar 3-sheet connectionSELECT *From Test.contract AJOIN Test.customer b on a.num = b.num2JOIN test.customer3 C on a.num = C.NUM3;
The connection is not necessarily followed by a join to the first table.SELECT *From Test.contract AJOIN Test.customer b on a.num = b.num2Left JOIN test.customer4 D on b.num2 = d.num4;SELECT *From Test.con
Tags: happy sharing feature for me select information from where BSPToday's work learning path is a database of small knowledge, at that time did not distinguish the why, hereby recorded share a sudden. As we all know, the tables of the database are all separate, but when we do a union query (multi-table query), we get the value returned by the database as if it were in a table, because the database generates a temporary table to return to the data information we want when we make a federated qu
Label:There are currently two tables, Sgroup and Sgroupuser, which are associated by Gkey, while the Sgroup table records the group, and the Sgroupuser record is the user in the group, so there is no data in the Sgroupuser. You need to use the left join to get the data: The LINQ syntax is as follows: var sg = ( from the dc.sgroup
in dc.sgroupuser on G.gkey equals Gu.gkey into L
Filter the condition and then establish the index of the related query field in the table in the same time. So it's pretty fast in the case of Big Data multi-table federated queries.SELECTM.*, SS. Sensorcode,ss. Sensorstatus,ss. Manufacturerid,ss. Electricity,ss. Voltage,ss. Minelectricity,ss. Minvoltage,ss. Temperature,ss. Statusupdtedate,ss. UpdateStatus, TP. Pricingstrategyid,tps. Freeduration,bat. Berthtypeid from(SELECTT.*, BS. Parkstatus,bs. Changetime, CA. Cantonname, SE. SectionName from
key name, without specifying the result field (that is, all mappings). By default, when a table is searched, the foreign key table is not queried, and the database query is not read until it is actually used, and if Include () is used, the specified foreign key table information is read when the table is read.Overload mode:Located in namespace System.Data.Entity.Infrastructurepublic dbqueryIt can be written like this:EF has generated the database mapping model classes for album and genre as wel
exists is faster than not.difference between in and =Select name from student where name in (' Zhang ', ' Wang ', ' Li ', ' Zhao ');Select name from student where Name= ' Zhang ' or name= ' li ' orName= ' Wang ' or name= ' Zhao 'The result is the same.Left\right join is an external connection, inner join is an inner joinThe external connection has the main table and from the table, the main table is
Assume that the table structure is: user_info table: role_info table: to query some data from the user_info table and role_info table, for example, when logging on to the system, in addition to the login name and password, you can also query additional information, such as user permissions, which may be connected. Here we use the left join: the SQL statement is as follows: selectu. *, r. role_name, r. right
First, the concept:
– Find all the records of the table on the left side of the leave join. The system will first use Table A and table B to make a Cartesian product, and then take table A as the base table, the table a part of the Cartesian product is null records. The final form of your results.
– When a left connection is made, it involves the primary table, t
Suppose the table's structure is:
User_info table:
Role_info table:
To query some data from table user_info and table role_info, such as when you log on to the system,
In addition to querying for information in terms of login names and passwords, additional information, such as user permissions, may be used to connect.
Here use LEFT JOIN to connect:
The SQL statement is as follows:
Select u.*,r.r
Entity class User, Dept. Each user has a dept attribute on the
-----------------------------------------------------------Model Class-------------------------------------------------------- ------------------
public class User implements Serializable
{
/**
* Serialization ID ID *
/
private static final long Serialversionuid = 1L;
Private Integer ID;
User name
private String userName;
Password
private String password;
Private Dept Dept;
Label:Oracle outer JOIN (OUTER join)
Left OUTER join (the table on the left is unrestricted)
Right outer join (the table on the right is unrestricted)
All-out connection (both the
Oracle outer JOIN (OUTER join)
Left OUTER join (the table on the left is unrestricted)
Right outer join (the table on the right is unrestricted)
All-out connection (both the l
Left join returns records that include all the records in the left table and the equivalent of the junction fields in the right tableRight join returns records that include all records in the right table and the junction fields in the left tableINNER
Left Join/right Join/inner Join relatedA concluding remark about left and right connections:Left join the Where only shadow right table, right join where only affects the
From: http://www.cnblogs.com/kevinGaoblog/archive/2012/07/05/2577410.html--Execute in Query Analyzer:--Build Table Table1,table2:CREATE TABLE table1 (ID int,name varchar (10))CREATE TABLE table2 (ID int,score int)INSERT INTO table1 Select 1, ' Lee 'INSERT INTO Table1 Select 2, ' Zhang 'INSERT INTO table1 Select 4, ' Wang 'Insert INTO table2 Select 1,90Insert INTO table2 Select 2,100Insert INTO table2 select 3,70such as table-------------------------------------------------Table1 | Table2--------
is as follows: SELECT * from A joins B on A.aid=b.bnameid run results as shown in 4: actually select * from A, A where a.aid= B.bnameid and select * from A JOIN B on A.aid=b.bnameid run the same result.Figure 4: Internal connection data2. Outer joins: There are two types of outer joins, one is the left join and the right joi
Let's say we have two tables. Table A is the tables on the left. Table B is the tables on the right. Each has four records, of which two records name is the same, as follows: Let's look at the different joinsA tableID Name1 Pirate2 Monkey3 Ninja4 spaghettiTable BID Name1 Rutabaga2 Pirate3 Darth Vade4 Ninja
1.INNER JOIN
SELECT * from TableA INNER JOIN TableB on ta
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.