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 9215541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:13:36+00:00 2026-06-18T02:13:36+00:00

I have joined tables of posts and tags like this: $this->db->select(‘*’); $this->db->from(‘posts’); $this->db->join(‘posts_tags’, ‘posts.post_id

  • 0

I have joined tables of posts and tags like this:

$this->db->select('*');
$this->db->from('posts');
$this->db->join('posts_tags', 'posts.post_id = posts_tags.post_id', 'left');
$this->db->join('tags', 'posts_tags.tag_id = tags.tag_id', 'left');

How do i loop through each post, and display a list of their respective tags.
For example:

post1: tag1, tag2
post2, tag1, tag3

At the moment, i can display the tags, but it return two rows for post 1 and two. The output now is:

post1: tag1
post1: tag2
post2: tag1
post2: tag3

How do i return one row for post, with all the related tags inside?

  • 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-06-18T02:13:38+00:00Added an answer on June 18, 2026 at 2:13 am

    Use group concat and group results

    $this->db->select('posts.*');
    $this->db->select('GROUP_CONCAT(posts_tags.tag_title) as TagTitles');
    $this->db->from('posts');
    $this->db->join('posts_tags', 'posts.post_id = posts_tags.post_id', 'left');
    $this->db->join('tags', 'posts_tags.tag_id = tags.tag_id', 'left');
    $this->db->group_by('posts.id');
    $this->db->get();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this elementary query: SELECT d.description, o.code FROM order_positions AS o LEFT JOIN
I have two joined tables. With print_r I am getting something like this Array
essentially I want to left join 3 tables I have joined 2 tables below
I have two tables that I have joined in a query like this IQueryable<Auction>
I have some data SELECT [field names] FROM [several joined tables] WHERE [some criteria
I have two tables joined together with entities like this (entities anonymized, and trimmed
I have an SQL query that selects from two inner joined tables. The select
I have two tables (Table A, Table B) joined with a join table (TableAB)
I used the mapping solution from this question to have a joined component. But
I have two tables like this: [tblFacilityHrs] id uid title description [tblFacilityHrsDateTimes] owner_uid startEventDate

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.