This article mainly introduces the join usage of the CI framework database query, and analyzes the use skills of the join method in the Database Query Process Based on the instance form, for more information about join queries in the CI framework database, see the example in this article. We will share this with you for your reference. The details are as follows:
Use each ID in Table A to query the information of this ID in the people table. The statement is as follows:
$this->db->from('A');$this->db->join('B', 'sites.id = B.id');
Use each ID in Table A to query the information of this ID in table B.
Note the SQL conventions. If a column name is repeated in two tables, you must add the table name and a "." Number before the column name. Therefore, sites. id indicates that the table where id is located is sites. When performing SQL multi-table queries, it is best to uniquely identify the column name to avoid ambiguity and make it clear to yourself.
For example, run the following statement:
$this->db->select('*');$this->db->from('blogs');$this->db->join('comments', 'comments.id = blogs.id');$query = $this->db->get();
It is equivalent to executing this SQL statement.
SELECT * FROM blogs JOIN comments ON comments.id = blogs.id
If you want to use multiple connections in the query, you can call this function multiple times.
To specify the JOIN type, you can use the third parameter of this function. Options include left, right, outer, inner, left outer, and right outer.
$ This-> db-> join ('comments', 'comments. id = blogs. id', 'left'); // generated: left JOIN comments ON comments. id = blogs. id