Join two table without like primary key

Posted on 2014-01-15
Medium Priority
Last Modified: 2014-01-21
I have a clients table and a address table that do not share a common primary key. How do I join these? See attached photo.
Question by:bjbrown
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
LVL 66

Expert Comment

by:Jim Horn
ID: 39782969
I dunno.  Close your eyes and use The Force?  Smoke, Magic, and Mirrors?  Mind reading?

Seriously, there are no columns these two tables have in common, at least in the image, so I don't see how you can pull this off.
LVL 34

Expert Comment

by:Brian Crowe
ID: 39783117
Either you are missing a joining table, the Address table has a ClientID, or the Client table has an AddressID.  Otherwise you're SOL

Author Comment

ID: 39783152
Sounds like I  need a table that has a field from the other two.
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

LVL 34

Expert Comment

by:Brian Crowe
ID: 39783168
It depends on the relationship you want between the two tables?

If you want a client to be able to have one or more addresses then place the ClientID in the Address table.

If you want multiple clients to be able to share the same address then place the AddressID in the Client table (unlikely).

If you want a many-to-many relationship where a single address could be shared by multiple clients and clients can have multiple address then Yes, you will need to create an intermediary join table.

CREATE TABLE ClientAddress
   ClientAddressID INT IDENTITY(1,1)  --optional
   AddressID INT NOT NULL,
   Label VARCHAR(100)  --optional

Author Comment

ID: 39783380
Okay perhaps I'm not describing this clearly, this is only a select where we are trying to pull information out of two tables since the client table does not contain the client's address and the address table does not contain the same primary key.
LVL 34

Expert Comment

by:Brian Crowe
ID: 39783612
If this is an existing system and you are sure that there is a relationship between the two tables then yes you are missing something.  Based on the information you provided there is no relationship between the tables.

It would help if you would provide the actual table definitions instead of incomplete screenshots.
LVL 66

Accepted Solution

Jim Horn earned 2000 total points
ID: 39783661
<Wild guesses>

Scroll down to the bottom of the bottom of each table and see if the Clients table has an Address ID column, or the Address table has a ClientsID.

Search through the database to see if there is a ClientsAddress (or something like it) table that is a M:M between Clients and Addresses.

Ask the source of this data how the two tables are related, and feel free to smack them if their response is 'they're not related'.

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question