l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2004 Apr 01 01:40

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] SQL question (mysql)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] SQL question (mysql)



On Wed, 31 Mar 2004, dylan wrote:

> Hello,
> 
> I am having a problem getting a query to work with MySQL 3.23.49
> 
> I have 3 tables, all which share a common key (user_id):
> 
> 1. volunteer_info (contains contact information) [key = user_id]
> 2. assignment_data (contains event assignment information) [key = user_id]
> fields include: user_id, event_id
> each record represents one event that any one volunteer is assigned to
> 
> 3. score_board (contains event participation information) [key = user_id]
> fields include: user_id, event_id, participation_status
> each record represents whether or not a person attended an event
> 
> there is a 1:1 relationship between each table, after a few 'where'
> statements are applied.

Why not have all of these columns in one table, then?

> As it stands right now i can access every person who was assigned to a given
> event (denoted by the variable $event_id) with the following query:
> 
> select volunteer_info.*
>        from assignment_data, volunteer_info
>        where volunteer_info.user_id = assignment_data.user_id
>        and assignment_data.event_id = $event_id
> 
> i am able to access the contact info and participation info with this query:
> 
> select volunteer_info.*, participation_status
>        from assignment_data, volunteer_info, score_board
>        where volunteer_info.user_id = assignment_data.user_id
>        and volunteer_info.user_id = score_board.user_id
>        and assignment_data.event_id = $event_id
>        and score_board.event_id = $event_id
> 
> HOWEVER!
> The score_board table may or may not contain records that match the second
> query, which causes an empty set to be returned - or worse yet - only some
> of the records that i am interested in. I have experimented with a left
> join, but am not quite sure how to accomplish this.
> 
> any ideas?

select
  vi.*
, sb.participation_status
from
  assignment_data ad
  INNER JOIN volunteer_info vi ON ad.user_id=vi.user_id
  LEFT JOIN score_board sb ON sb.user_id=ad.user_id
where ad.event_id = $event_id
  and sb.event_id = $event_id

If they don't go where they are assigned, it looks like you won't see them
in this query.

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k
---------------------------------------------------------------------------

_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.