If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-04, 11:09
JamVan JamVan is offline
Registered User
 
Join Date: Mar 2004
Location: Ottawa
Posts: 1
Query Help

Can someone view the following code and tell me why I am getting duplicate name records returning?

SELECT DISTINCT [Input Table].ID, [Input Table].Last_Name, [Input Table].First_Name, [Input Table].Cost_Center, April.April_Premium, Aug.Aug_Premium, Dec.Dec_Premium, Feb.Feb_Premium, Jan.Jan_Premium, July.July_Premium, June.June_Premium, May.May_Premium, Nov.Nov_Premium, Oct.Oct_Premium, Sep.Sep_Premium
FROM (((((((((((April INNER JOIN Aug ON April.ID = Aug.ID) INNER JOIN Dec ON April.ID = Dec.ID) INNER JOIN Feb ON April.ID = Feb.ID) INNER JOIN [Input Table] ON April.ID = [Input Table].ID) INNER JOIN Jan ON April.ID = Jan.ID) INNER JOIN July ON April.ID = July.ID) INNER JOIN June ON April.ID = June.ID) INNER JOIN March ON April.ID = March.ID) INNER JOIN May ON April.ID = May.ID) INNER JOIN Nov ON April.ID = Nov.ID) INNER JOIN Oct ON April.ID = Oct.ID) INNER JOIN Sep ON April.ID = Sep.ID;


Thanks in advance for any help.
Reply With Quote
  #2 (permalink)  
Old 03-05-04, 11:44
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Query Help

No, one would need to know the keys of the tables. But what a design: a table per month! Why not just have one Premium table with a month column?
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 03-05-04, 12:08
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Did you maybe want to put a leash on the thing by insisting that something in the WHERE clause be equal to the [INPUT TABLE].ID value ??? Methinks you are getting a bounded cartesian join.

-PatP
Reply With Quote
  #4 (permalink)  
Old 03-05-04, 12:24
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally posted by Pat Phelan
Did you maybe want to put a leash on the thing by insisting that something in the WHERE clause be equal to the [INPUT TABLE].ID value ??? Methinks you are getting a bounded cartesian join.

-PatP
That is there, between the join to Feb and the join to Jan - just to add to our confusion!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 03-05-04, 12:36
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Quote:
Originally posted by andrewst
That is there, between the join to Feb and the join to Jan - just to add to our confusion!
FWIW, here's a somewhat tidied up version of the query:
PHP Code:
SELECT DISTINCT
       
[Input Table].ID,
       [
Input Table].Last_Name,
       [
Input Table].First_Name,
       [
Input Table].Cost_Center,
       
April.April_Premium
       
Aug.Aug_Premium,
       
Dec.Dec_Premium,
       
Feb.Feb_Premium,
       
Jan.Jan_Premium,
       
July.July_Premium,
       
June.June_Premium,
       
May.May_Premium,
       
Nov.Nov_Premium,
       
Oct.Oct_Premium,
       
Sep.Sep_Premium
FROM 
( ( ( ( ( ( ( ( ( ( (April INNER JOIN Aug ON April.ID Aug.ID
                    
INNER JOIN Dec ON April.ID Dec.ID
                  
INNER JOIN Feb ON April.ID Feb.ID
                
INNER JOIN [Input TableON April.ID = [Input Table].ID
              
INNER JOIN Jan ON April.ID Jan.ID
            
INNER JOIN July ON April.ID July.ID
          
INNER JOIN June ON April.ID June.ID
        
INNER JOIN March ON April.ID March.ID
      
INNER JOIN May ON April.ID May.ID
    
INNER JOIN Nov ON April.ID Nov.ID
  
INNER JOIN Oct ON April.ID Oct.ID
INNER JOIN Sep ON April.ID Sep.ID
Quite why we start with April, then August, then December... I don't know!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #6 (permalink)  
Old 03-05-04, 12:41
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Quote:
Originally posted by andrewst
That is there, between the join to Feb and the join to Jan - just to add to our confusion!
I just hate it when I miss something like that. Ugly code (looks like MS-Access generated), but I should still have read it more carefully.

Is there any possibility of GIGO? Could there be two (or more) rows with the same id in any of the tables (maybe from different years)?

-PatP
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On