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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:14:43+00:00 2026-06-01T06:14:43+00:00

What I am trying to do is to access the proper row in a

  • 0

What I am trying to do is to access the proper row in a table, so that it returns the right location name, address, etc. The address is returned correctly, but there are three results rather than one. These are our various international locations.

Either my tables aren’t normalized properly or I’m writing my query incorrectly. I can’t figure out which. Maybe a little of both. Here are my tables:

DEALERS TABLE: 

channel_partner_id    company
------------------    --------
626                   Company Inc.
626                   Company GmBH
626                   Company Ltd.

DEALERS_LOCATIONS TABLE:

channel_partner_id    location_id
------------------    -----------
626                   18
626                   19
626                   20

LOCATIONS TABLE:

location_id           address                name_url
----------            --------------------   -------
18                    1234 Anywhere St.      anywhere-st
19                    3245 Nowhere St.       nowhere-st
20                    90 Everywhere St.      everywhere-st

I want to join them on the name_url.

So here’s my query in CodeIgniter/Active Record (which is translated into standard MySQL easy enough):

$this->db->where('l.name_url', $name_url);
$this->db->join('all_dealers_locations dl', 'dl.channel_partner_id = d.channel_partner_id', 'inner');
$this->db->join('all_locations l', 'l.location_id = dl.location_id', 'inner');
$row = $this->db->get('all_dealers d')->row();

But I get back three results from this. Why, if I am using the where clause of the name_url (which is being passed properly into the function)? Is it the type of join I have? I tried left and outer and that didn’t help.

What am I doing wrong?

  • 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-01T06:14:44+00:00Added an answer on June 1, 2026 at 6:14 am

    Your tables have some issues.

    The big red flag is that dealers has multiple rows with the same id (which means that channel_partner_id can not be the primary key).

    This is a problem because it looks like dealers_locations is supposed to be an intersection table. The standard way to implement such a table is to take the primary keys of the two tables, which in this case would be locations and dealers. Since dealer_locations doesn’t have the primary key of dealers, it’s not going to work.

    Here’s how I would implement this instead:

    create table dealers (
      channel_partner_id   int primary key,
      name                 varchar(30)
    );
    
    create table locations (
      location_id  int primary key,
      address      varchar(30),
      name_url     varchar(30)
    );
    
    create table dealer_locations (
      location_id int,
        foreign key (location_id) references locations(location_id),
      channel_partner_id int,
        foreign key (channel_partner_id) references dealers(channel_partner_id),
      primary key (location_id, channel_partner_id)
    );
    

    Note the two-part primary key for dealer_locations.

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

Sidebar

Related Questions

I'm trying to access a member structs variables, but I can't seem to get
I am trying to access a WCF web service, that is using two way
I'm trying to write a behavior that will give my models access to a
I'm trying to access servletContextin a controller like so, but keep getting null pointer
I am trying to make a php login page that allows users to access
I'm trying to access my first ruby project. After navigating to the proper directory
I am trying to access the google calendar using gdata. but the application closes
Trying to access a Servlet from a button on HTML page //Html Page FORM
Im trying to access the Magento customer session in another part of my website.
Im trying to access a Sql CE 2005 database on a windows mobile device

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.