Home > Backend Development > PHP Tutorial > How to Exclude Records Using Subqueries with CodeIgniter\'s Query Builder?

How to Exclude Records Using Subqueries with CodeIgniter\'s Query Builder?

Barbara Streisand
Release: 2024-11-18 07:31:02
Original
401 people have browsed it

How to Exclude Records Using Subqueries with CodeIgniter's Query Builder?

Selecting Records Using CodeIgniter's Query Builder with Subquery Exclusion

CodeIgniter's query builder provides various methods for constructing SQL queries. One common scenario involves excluding records based on a subquery. To accomplish this, the where() method can be employed, as demonstrated below:

->select('*')
->from('certs')
->where('`id` NOT IN (SELECT `id_cer` FROM `revokace`)', NULL, FALSE);
Copy after login

The NULL, FALSE parameters within the where() method instruct CodeIgniter to refrain from escaping the query, preserving its intended format.

Alternatively, the subquery library can be utilized for greater flexibility:

->select('*')
->from('certs')
->subquery->start_subquery('where_in')
->subquery->select('id_cer')
->subquery->from('revokace')
->subquery->end_subquery('id', FALSE);
Copy after login

This method provides a convenient mechanism for constructing subqueries within the framework of CodeIgniter's query builder, allowing for more complex and dynamic data retrieval operations.

The above is the detailed content of How to Exclude Records Using Subqueries with CodeIgniter\'s Query Builder?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template