Join repeats records again?

Asked

Viewed 105 times

1

I have tables in the database that relate. A (t.a) has four lines that relate to the other four lines of (t.b) The query is made by means of a (user.id) that exists in the two tables.

The problem happens in the return of the query that repeats 12 more lines ? How can I treat this error ? Below follows the code and link:

public function planstypes_head($elev_opename_id) {
   $this->db->select('*');
   $this->db->from('elev_plans_types');
   $this->db->join('elev_share_plans', 'elev_share_plans.elev_opename_id = elev_plans_types.elev_opename_id' , 'left');
   $this->db->where('elev_plans_types.elev_opename_id', $elev_opename_id);
   $query = $this->db->get();
   return $query->result(); 
}

Link: http://elevsaude.webstrucs.com/tabelas/elevsaude/operadora/1

  • Depending on the query Join returns 'duplicated' records, has some special reason to use the left join?

  • 2
  • Organizes data from table b with a. Without the listing it is not synchronized: data. a, data. a, data. a, data. a, data. a.

  • Exchange the left for inner see if it shows the expected result.

  • only lists one record.

  • I need you to list the other related.

  • 1

    Add the structures of your tables. How many records do you have in each one? What is the correct query return? This can be useful: Correct way to make a great Inner Join

Show 2 more comments

2 answers

2

Good afternoon. I think if I change the line

$this->db->select('*');

To

$this->db->select('elev_plans_types.*');

You will be right. It turns out that if you just put '*', you’re having the table data selected elev_plans_types and table elev_share_plans. I hope I’ve helped.

Oss

  • In this case yes, but the data that needs to be listed is based on the parameter.

1

You should group the records by the main field you are looking for. I believe that if you do $this->db->group_by("elev_plans_types.elev_opename_id"); work.

  • I tried too, but it filters only one related line. The remaining three are gone ?

  • What main field do you want to appear even if some others are null? Usually this is why you have to group

  • elev_plans_types e elev_share_plans.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.