PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > ms.sqlserver.server > inner join on 3 tables - the result returned is duplicated
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
inner join on 3 tables - the result returned is duplicated

Réponse
 
LinkBack Outils de la discussion
Vieux 19/05/2008, 15h34   #1
Whiskey
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut inner join on 3 tables - the result returned is duplicated

table 1
abc
241060 3332.29

table 2
abc def
241060 OH_Adm_InsPremOth

table 3
def
OH_Adm_InsPremOth 3332.29

result of inner join table 1 abc = table 2 abc
and
inner join table 2 def = table 3 def

241060 3332.29 OH_Adm_InsPremOth 3332.29

The above is fine but if I have

table 1
abc
241060 3332.29
241070 5000.00

table 2
abc def
241060 OH_Adm_InsPremOth
241070 OH_Adm_InsPremOth

table 3
def
OH_Adm_InsPremOth 8332.29

result of inner join table 1 abc = table 2 abc
and
inner join table 2 def = table 3 def

241060 3332.29 OH_Adm_InsPremOth 8332.29
241060 3332.29 OH_Adm_InsPremOth 8332.29
241070 5000 OH_Adm_InsPremOth 8332.29
241070 5000 OH_Adm_InsPremOth 8332.29


  Réponse avec citation
Vieux 19/05/2008, 15h46   #2
Plamen Ratchev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: inner join on 3 tables - the result returned is duplicated

What is the query that you wrote? Given the sample data and the joins there
should be no duplicate rows in the result set. Try this:

SELECT A.abc, B.def
FROM Table1 AS A
JOIN Table2 AS B
ON A.abc = B.abc
JOIN Table3 AS C
ON B.def = C.def;

HTH,

Plamen Ratchev
http://www.SQLStudio.com

  Réponse avec citation
Vieux 19/05/2008, 16h05   #3
John Bell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: inner join on 3 tables - the result returned is duplicated

"Whiskey" <Whiskey@discussions.microsoft.com> wrote in message
news:667F45B4-4660-445B-A195-DA542251CD94@microsoft.com...
> table 1
> abc
> 241060 3332.29
>
> table 2
> abc def
> 241060 OH_Adm_InsPremOth
>
> table 3
> def
> OH_Adm_InsPremOth 3332.29
>
> result of inner join table 1 abc = table 2 abc
> and
> inner join table 2 def = table 3 def
>
> 241060 3332.29 OH_Adm_InsPremOth 3332.29
>
> The above is fine but if I have
>
> table 1
> abc
> 241060 3332.29
> 241070 5000.00
>
> table 2
> abc def
> 241060 OH_Adm_InsPremOth
> 241070 OH_Adm_InsPremOth
>
> table 3
> def
> OH_Adm_InsPremOth 8332.29
>
> result of inner join table 1 abc = table 2 abc
> and
> inner join table 2 def = table 3 def
>
> 241060 3332.29 OH_Adm_InsPremOth 8332.29
> 241060 3332.29 OH_Adm_InsPremOth 8332.29
> 241070 5000 OH_Adm_InsPremOth 8332.29
> 241070 5000 OH_Adm_InsPremOth 8332.29
>
>


Hi

Post usable DDL and sample data see
http://www.aspfaq.com/etiquette.asp?id=5006 along with the whole statements
you are trying to execute.

John

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09595 seconds with 11 queries