
Re: Complex mysql (joins?)
SarahAtkinson wrote:
I have a set of database tables.
three contain user info, event info and fee info
one table contains the id's linking user to event
one table links fee's to events
one table links users to fees
I'm thinking this might be a little too complicated and maybe I should just have fees in with events although not all fees are associated with an event.
what I want to do is with the User ID I want to get the events associated with that user through the event/user table then compare them to the event/fee table and get the fee ids associated with (if any) of the events.
then I want to take that fee id and user id and insert them into the fee/user table.
I'm not very good with joins and I think that is what I need to use. and sugestions?
Sarah
It'd be easier... if you pasted your database structure all though heres an attempt:
Code:
SELECT * FROM users AS a LEFT JOIN events AS b ON (a.id = b.user_id) LEFT JOIN fees AS c ON (b.id = c.event_id) WHERE a.id = 'USER_ID'
Hopefully this will be of some help? If you don't figure it out paste your database structure and I'll see if I can't help you more.
_________________
Software Engineer
http://www.tuxmafia.com