CI framework database query join Usage Analysis _ php instance

Source: Internet
Author: User
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

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.