In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the MySql connection query example analysis, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Refined solution of MySql join query
In order to summarize and share the knowledge, we practice and summarize the common queries.
Data preparation, including two tables, tuser and ttable. Tuser and ttable have an one-to-many relationship.
The tuser table is structured as follows:
Name www.2cto.com
Types
Remarks
Id
Integer
Primary key
Name
Varchar (50)
User name
Password
Varchar (50)
User password
Sex
Varchar (20)
User gender
The ttable table is organized as follows:
Name
Types
Remarks
Id
Integer
Primary key
Name
Varchar (50)
Name
Userid
Integer
User id
Build a table sentence:
[sql]
Create table tuser (id Integer primary key
Name varchar (50)
Password varchar (50)
Sex varchar (20)
);
Create table ttable (id Integer primary key
Name varhcar (50)
Userid Integer
); www.2cto.com
Insert data statement
[sql]
Insert into tuser (id, name, password,sex) values (1Jing 'Chinese', 'test','m')
Insert into tuser (id, name, password,sex) values (2Jing 'Chinese', 'test','m')
Insert into ttable (id,name, userid) values
Insert into ttable (id,name, userid) values (2 records2)
Insert into ttable (id,name, userid) values (3 records2)
1. Left outer connection
Select * from ttablet left join tuser u on t.userid=2 and t.useridroomu.id; the result is as follows:
Based on the left side table (ttable), all the data satisfying the conditions are queried, while the right table (tuser) does not meet the conditions and appears null completion.
2. Right outer connection
Select * from ttable t right join tuser u on t.userid=2 and t.userid=u.id shows the following result: www.2cto.com
Based on the right table (tuser), all the data that meets the conditions are queried, while the left table (ttable) does not meet the conditions, and null completion occurs.
3. Internal connection
The result of select * from ttable,tuser; is as follows:
In the form of Cartesian product. Let An and B be sets, with the element x in An as the first element and the element y in B as the second element to form an ordered pair. the set of all such ordered pairs is called the Cartesian product of An and B, denoted as A × B.
In, the relationship An is, the specific content is {,}, and the relationship B is {}.
Then A × B = {,}
If we make the choice of the first column = the third column, and then do the projection of only the first, second, and third columns, we will get {,}. Through the three operations of relational algebra, we can find out the age of each person.
Thank you for reading this article carefully. I hope the article "sample Analysis of MySql connection query" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.