PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > Outer Joining Multiple Tables
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Outer Joining Multiple Tables

Réponse
 
LinkBack Outils de la discussion
Vieux 07/01/2008, 22h31   #1
DonO
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Outer Joining Multiple Tables

I have 3 tables that I want to join like so...

table 1:
USER
---------
uid
first_name
last_name


table 2:
SIGNOFF
--------------
uid
item_name


table 3:
COMPLETED
--------------------
user_uid
signoff_uid
date_complete


If I use table 3 to join them like so everyone signed off for UID 1 of
the signoff, I can do this:

SELECT s.item_name, u.first_name, u.last_name, c.date_completed
FROM user u, signoff s, completed c
WHERE u.uid = c.user_uid
AND c.signoff_uid = s.uid
AND s.uid = 1

What I'd like to do is list all employees regardless of their signoff
status. Nothing will be in the COMPLETED table though for their id. I
don't know how to do an outer join "once removed" like that.

Thanks for any .

D.

  Réponse avec citation
Vieux 07/01/2008, 22h45   #2
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Outer Joining Multiple Tables

DonO wrote:
>I have 3 tables that I want to join like so...
>
> table 1:
> USER
> ---------
> uid
> first_name
> last_name
>
>
> table 2:
> SIGNOFF
> --------------
> uid
> item_name
>
>
> table 3:
> COMPLETED
> --------------------
> user_uid
> signoff_uid
> date_complete
>
>
> If I use table 3 to join them like so everyone signed off for UID 1 of
> the signoff

The above makes no sense???

> I can do this:
>
> SELECT s.item_name, u.first_name, u.last_name, c.date_completed
> FROM user u, signoff s, completed c
> WHERE u.uid = c.user_uid
> AND c.signoff_uid = s.uid
> AND s.uid = 1
>
> What I'd like to do is list all employees regardless of their signoff
> status.

SELECT
*
FROM user

As a general rule, always use explict JOINs with their own join criteria
rather than implicit comma joins where the join criteria gets mixed in with
the WHERE clauses.



  Réponse avec citation
Vieux 07/01/2008, 22h56   #3
DonO
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Outer Joining Multiple Tables

Ok. I'll try to explain better...

This will work to get everyone who is in the system:

SELECT signoff.item_name, user.first_name, user.last_name,
completed.date_complete
FROM signoff
JOIN completed ON completed.signoff_uid = signoff.uid
JOIN user ON user.uid = complete.user_uid
WHERE signoff.uid = '1' ;

That gets me the name off the required signoff, the user's name, and
the date they signed off.

I'd like to list all the employee's that have not signed off too with
a NULL for the date_complete.

Thanks,
D.

On Jan 7, 4:45 pm, "Paul Lautman" <paul.laut...@btinternet.com> wrote:
> DonO wrote:
> >I have 3 tables that I want to join like so...

>
> > table 1:
> > USER
> > ---------
> > uid
> > first_name
> > last_name

>
> > table 2:
> > SIGNOFF
> > --------------
> > uid
> > item_name

>
> > table 3:
> > COMPLETED
> > --------------------
> > user_uid
> > signoff_uid
> > date_complete

>
> > If I use table 3 to join them like so everyone signed off for UID 1 of
> > the signoff

>
> The above makes no sense???
>
> > I can do this:

>
> > SELECT s.item_name, u.first_name, u.last_name, c.date_completed
> > FROM user u, signoff s, completed c
> > WHERE u.uid = c.user_uid
> > AND c.signoff_uid = s.uid
> > AND s.uid = 1

>
> > What I'd like to do is list all employees regardless of their signoff
> > status.

>
> SELECT
> *
> FROM user
>
> As a general rule, always use explict JOINs with their own join criteria
> rather than implicit comma joins where the join criteria gets mixed in with
> the WHERE clauses.


  Réponse avec citation
Vieux 08/01/2008, 09h37   #4
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Outer Joining Multiple Tables

DonO wrote:
> Ok. I'll try to explain better...
>
> This will work to get everyone who is in the system:
>
> SELECT signoff.item_name, user.first_name, user.last_name,
> completed.date_complete
> FROM signoff
> JOIN completed ON completed.signoff_uid = signoff.uid
> JOIN user ON user.uid = complete.user_uid
> WHERE signoff.uid = '1' ;
>
> That gets me the name off the required signoff, the user's name, and
> the date they signed off.
>
> I'd like to list all the employee's that have not signed off too with
> a NULL for the date_complete.
>
> Thanks,
> D.
>


Please do not top post.

Can you supply some context for these tables?
What is signoff.item_name?
What is the significance of signoff.uid = '1'?
If the above query gets "everyone who is in the system", how can there be
more employees (note no apostrophe) to get?


  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 12h02.


É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,13493 seconds with 12 queries