PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 26th, 2012, 05:03 PM
slarabee slarabee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 slarabee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 24 sec
Reputation Power: 0
Joining 2 Tables on identicle columns eliminating duplicates

Hello,

I have 2 tables in the same database with different data except that one column (in both tables) Route_ID has the same route numbers (except one may not have all of the same routes as the other.

I need to join the tables on those Route_IDs and I am having a difficult time understanding how the joins will work. Any help in understand how joins operate would be helpful.

A little more info:

Table A contains Route_ID plus a date

Table B contains Route_ID and StartDate and EndDate

I need to query out distinct on the Route_ID in both tables and also on a certain date in Table A and in the range of StartDate and EndDate for the same date.

I have everything working but cannot figure out how to make the data join together so that my final list shows one route entry date and range for each route that falls into the parameters for both.

Thanks,

Sean

Reply With Quote
  #2  
Old November 27th, 2012, 03:39 AM
swampBoogie swampBoogie is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2003
Location: Paris Uppland
Posts: 2,350 swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level)swampBoogie User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 4 Days 7 h 38 m 35 sec
Reputation Power: 390
Basically it would be like

Code:
select <columnsOfInterest>
  from route_table_1
  join route_table_2
    on route_table_1.route_id = route_table_2.route_id
 where route_table_1.date = <someDateValue>
   and <someDateValue> between route_table_2.startDate and route_table_2.endDate


If you need more help you have to give some sample data and the expected result.

Reply With Quote
  #3  
Old November 27th, 2012, 03:04 PM
slarabee slarabee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 3 slarabee User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 11 m 24 sec
Reputation Power: 0
Thank you swampBoogie

I actually figured it out yesterday once I understood the difference between inner and outer joins I ran:

SELECT
route_list_sb032206."Route_ID",
route_list_sb032206."StartDate",
route_list_sb032206."EndDate",
route_list_sb032206."Carrier_ID",
route_list_sb032206."SB_Carrier_Name",
route_list_032206."Date",
route_list_032206."Route_ID",
route_list_032206."Carrier_ID",
route_list_032206."Carrier_Name",
route_list_032206."Occupant_Addr",
route_list_032206."Occupant_City",
route_list_032206."State",
route_list_032206."Zip"
FROM

public."route_list_sb032206"

INNER JOIN public."route_list_032206" on route_list_sb032206."Route_ID" = route_list_032206."Route_ID"

Order by route_list_sb032206."Route_ID", route_list_032206."Route_ID";

And this gave me what I needed.

Thanks again for your response though.

Sean

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Joining 2 Tables on identicle columns eliminating duplicates

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap