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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:32:44+00:00 2026-05-21T22:32:44+00:00

I`m using two tables to hold information about cars. In the first table there

  • 0

I`m using two tables to hold information about cars. In the first table there is a information about car manufacturer etc and the second contain images for each car. My tables looks like this:

car_information    car_images
---------------    ---------
id       | 2       car_id 2 | img1
car_make | Fiat    car_id 2 | img2
color    | Blue    car_id 2 | img3
etc ....

As you can see each car has three images.

Here is query i`m using to fetch the result;

 $this->db->select('
           c.id,
           c.car_make,
           c.car_color,
           ci.image
        ');       

  $this->db->from('car_information c');
  $this->db->join('car_images ci', 'ci.car_id = c.id', 'left');
  return $this->db->get();  

Everything works fine but the problems i`m facing is that results are duplicated.

For example:

2 Fiat Blue img1
2 Fiat Blue img2
2 Fiat Blue img3

3 BMW white img4
3 BMW white img5

What to do so the result to looks like this

2 Fiat Blue img1 | img 2 | img 3

I want to get all information in single row.
I know that I can you two queries, but I`m wondering how to do with a single ?

  • 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-21T22:32:44+00:00Added an answer on May 21, 2026 at 10:32 pm

    Add the following line: $this->db->group_by('c.id');

    like so:

     $this->db->select('
               c.id,
               c.car_make,
               c.car_color,
               ci.image
            ');       
    
      $this->db->from('car_information c');
      $this->db->join('car_images ci', 'ci.car_id = c.id', 'left');
      $this->db->group_by('c.id');
      return $this->db->get();  
    

    This will work in MySQL because group by can be used as a synonym for distinct in MySQL.

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

Sidebar

Related Questions

using php and mysql I have two tables, a users table and a profiles
I'm using two tables. First (friendlist), which contains users who are on the list
I am using SQL 2005. Table one, LinkedDocumentFolderTable, contains the names and information about
I am new to SQL, and have two tables that hold data(I am using
I'm using two tables in the database. The first contains data related to the
Multiple categories selection system for Article Earlier M using two tables articles & categories
Can i join two tables using LINQ for NHibernate like I can do in
How to create a relation between two tables using PHPMyAdmin?
I need to perform data validation of two tables using Selenium . Given a
I have two tables which I want to join together using a left outer

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.