Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7021807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:29:56+00:00 2026-05-27T23:29:56+00:00

How do i write in codeigniter in active record the following query? select tbl_list.id,

  • 0

How do i write in codeigniter in active record the following query?

select tbl_list.id, tbl_list_items.name
from tbl_list
join tbl_list_items
on tbl_list_items.id=(select tbl_list_items.id from tbl_list_items where list_id=tbl_list.id order by tbl_list_items.item_no asc LIMIT 1)

Update:

This is what i come out with but it does not do the job.

$this->db->select($this->table_list.'.*');
$this->db->from($this->table_list);
$sub = $this->subquery->start_subquery('join','',$this->table_list_items.'.id');
$sub->select('id')->from($this->table_list_items)->where('list_id','tbl_list.id')->order_by($this->table_list_items.'item_no','asc')->limit('1');
$this->subquery->end_subquery('list_items');

Appreciate any helps. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:29:56+00:00Added an answer on May 27, 2026 at 11:29 pm

    Review the Active Record methods available to you in CodeIgniter.

    Then review a CI library to extend it to handle subqueries available on CodeIgniter

    There is a walk-through about how CI is doing this under-the-hood

    Found a github codebase for implementing subqueries in CodeIgniter 1.7 and 2.x (see link)

    EDIT:

    Revised Code is below to assist. You can also check out the 4th link’s examples.

    To replicate what you’er trying to do, the code would be similar to (this is un-tested… but hopefully starts you on the right path):

    $this->db->select('tbl_list.id, tbl_list.names');
    $this->db->from('tbl_list');
    $sub = $this->subquery->start_subquery('join', 'left', 'tli.id = tbl_list.id');
    $sub->select('tbl_list_items.id')->from('tbl_list_items')->where('tbl_list_items.list_id=tbl_list.id ');
    $sub->db->order_by('ASC');
    $sub->db->limit(1);
    $this->subquery->end_subquery('tli');
    

    The key is this statement: $this->subquery->end_subquery(‘tli’);
    What happens there, is that it treats the result of the subquery as AS tli so that you can reference it in tli.id.

    Hope this helped!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to write following query through codeigniter's db helper class, guide me plz
The following line is giving an error message. $query = 'SELECT * FROM products
I wrote an active record query in CodeIgniter and then I realised that I
In php Codeigniter you can write: $this->db->select('username')->from->('users')->where('id',5); Do you know any good lib for
i want to write this query on codeigniter way. the query is: SELECT M.
I am wanting to write this query: SELECT u.userId, uil.interestId, url.regionId FROM users u
I want to build a query like SELECT username from users WHERE login_attempts >
I write this from in Codeigniter as a form_view.php . <?php echo form_open('form'); ?>
For re write url i am using $route['controller/function name/([a-z]+)'] = 'controller/function name/$1'; in codeigniter,
I want to redirect to www.yahoo.com from my codeIgniter application. I write code like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.