In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use join in thinkphp5". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to use join in thinkphp5.
In thinkphp5, join is used to query data from two or more tables according to the relationship between columns in these tables, which is one of the methods of coherent operation. The result returned is a model object with the syntax of "join (table name to be associated and alias [association condition [association type]])".
This article operating environment: Windows10 system, ThinkPHP5 version, Dell G3 computer.
What is the use of join in thinkphp5
The JOIN method is also one of the coherent operations that is used to query data from two or more tables based on the relationship between the columns in those tables.
Description
Object join (mixed join [, mixed $condition = null [, string $type = 'INNER']])
Parameters.
Join: the (full) table name and alias to be associated, which can be written in three ways:
Write 1: ['full table name or subquery' = > 'alias']
Write 'full table name alias' with the letter 2VR.
Write the name of the table without the prefix of the data table.
Condition: the association condition. Can be a string or an array, and when it is an array, each element is an association condition.
Type: the association type. Can be: INNER, LEFT, RIGHT, FULL, case-insensitive, default is INNER.
Return value: model object
There are usually several types of join, and different types of join operations affect the results of the data returned.
INNER JOIN: equivalent to JOIN (default JOIN type), returns a row if there is at least one match in the table
LEFT JOIN: returns all rows from the left table even if there is no match in the right table
RIGHT JOIN: returns all rows from the right table even if there is no match in the left table
FULL JOIN: returns a row as long as there is a match in one of the tables
Examples are as follows:
Db::table ('think_artist')-> alias (' a')-> join ('think_work wrestling page.id = w.artistfolid')-> join (' think_card cantilever.cardpaperid = c.id')-> select () Db::table ('think_artist')-> alias (' a')-> join ('_ _ WORK__ winters grammatical .cardweights. Artistfolds')-> join ('_ _ CARD__ winters grammatical a.cardweights. Cardholders c.id')-> select (); $join = [['think_work wrought mills a.cardholders. Artists.id'], [' think_card cantilevers parallela.cardweights Db::table ('think_user')-> alias (' a')-> join ($join)-> select ()
The effect of the above three kinds of writing is the same, _ _ WORK__ and _ _ CARD__ will be converted to think_work and think_card at the final parsing. Note: in this way, the middle table name needs to be capitalized.
If you do not want to use an alias, the following condition should use the full name of the table, which can be used in the following way
Db::table ('think_user')-> join (' _ WORK__','__ARTIST__.id = _ _ WORK__.artist_id')-> select ()
INNER JOIN is used by default. If you need to use other JOIN methods, you can change it to
Db::table ('think_user')-> alias (' a')-> join ('word wicked journal recording a.id = W. artistocridwritten grammar recorder RIGHT')-> select ()
The table name can also be a subquery
$subsql= Db::table ('think_work')-> where ([' status'= > 1])-> field ('artist_id,count (id) count')-> group (' artist_id')-> buildSql (); Db::table ('think_user')-> alias (' a')-> join ([$subsql= >'w'], 'a.artist_id = w. Artistroomid')-> select ()
Because the statement returned by buildSql has (), there is no need to add () at both ends.
At this point, I believe you have a deeper understanding of "how to use join in thinkphp5". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue 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.