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

  • Home
  • SEARCH
  • 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 8104937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:01:31+00:00 2026-06-06T00:01:31+00:00

I have a mails table which is my main tables for manipulating mails. I

  • 0

I have a mails table which is my main tables for manipulating mails. I also have mails_sent and mails_dates which has FK connecting them with mails and contain data as follows mails_dates – a single mail could have more than one date set for sending so I have realtion 1:N where N are all the dates set from the user for the mail to be send and mails_sent – after a mail is sent a new record is added in this table with the id of the mail and the date it was sent. Because as I mentioned a mail could be sent more than once here the relation is also 1:N where N here represents the different dates when a mail was sent.

I need to show this info in a UI. First I had to show only the sending dates and I user this:

$this->db->select("mails.id, mails.subject, mails.dt_created, mails.groups");
        $this->db->select("GROUP_CONCAT(DATE_FORMAT( mails_dates.dt_sending_date, '%d-%m-%Y')) AS sending_dates", FALSE );
        $this->db->join('mails_dates','mails_dates.mail_id = mails.id', 'left');
        $this->db->join('mails_sent','mails_sent.mail_id = mails.id', 'left');


        $this->db->from('mails');
        $this->db->group_by('mails.id');
        $res = $this->db->get()->result_array();

        return $res;

When I was using this everything was fine I was getting a string with all the dates in it. But the problem is when I try to get the dates when a mail was sent. I added one more select:

$this->db->select("GROUP_CONCAT(DATE_FORMAT( mails_sent.dt_sent, '%d-%m-%Y')) AS sent_dates", FALSE );

making my query looks like this:

    $this->db->select("mails.id, mails.subject, mails.dt_created, mails.groups");
    $this->db->select("GROUP_CONCAT(DATE_FORMAT( mails_sent.dt_sent, '%d-%m-%Y')) AS sent_dates", FALSE );
    $this->db->select("GROUP_CONCAT(DATE_FORMAT( mails_dates.dt_sending_date, '%d-%m-%Y')) AS sending_dates", FALSE );
    $this->db->join('mails_dates','mails_dates.mail_id = mails.id', 'left');
    $this->db->join('mails_sent','mails_sent.mail_id = mails.id', 'left');

    $this->db->from('mails');
    $this->db->group_by('mails.id');
    $res = $this->db->get()->result_array();

    return $res;

But the problem is that If sending_dates contains let’s say – 6 values, and sent_dates has only one I end up with a string containing 6 times the value of sent_dates. This is in production so I don’t have a lot of records but the same happens with a query where I have 2 sending_dates and 1 record for sent_dates still I get 2 times the record from sent_dates.

How can I fix this?

Thanks

Leron

  • 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-06T00:01:37+00:00Added an answer on June 6, 2026 at 12:01 am

    Ok, I found the solution, here it is:

    $this->db->select("GROUP_CONCAT(DISTINCT(DATE_FORMAT(mails_sent.dt_sent, '%d-%m-%Y'))) AS sent_dates", FALSE );
    

    In other words just use DISTINCT.

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

Sidebar

Related Questions

I have seen some mails which has HTML content embedded in them. The content
i have a table campaign which has details of campaign mails sent. campaign_table: campaign_id
I have one column in my table which will store data in string format
Hey guys, I currently have a root table view which has a toolbar at
I have two tables, first table structure (data) : -id -name -title -mail -source_id
I have a list of e-mails from one database which I want to check
I have a list of e-mail addresses, some of them are in my table,
I have a MySQL table implementing a mail queue, and I use it also
I have two tables in my database: Company table (ID, CompanyName, CompanyUsername, CompanyPassword) Employee
I have 2 Tables, User and Mail. In User Table i have 2 columns

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.