Forum Moderators: coopster

Message Too Old, No Replies

using JOINs in MySQL query

         

Sarah Atkinson

4:40 pm on Jun 28, 2005 (gmt 0)

10+ Year Member



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 a fee field in the events table although not all fees are associated with an event and not all events have fees. In fact less then 5% of the events have fees. So the way I have it is probably best.

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.

than 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

Sarah Atkinson

5:46 pm on Jun 28, 2005 (gmt 0)

10+ Year Member



I've been doing some reading on joins and is this it.

SELECT event.fee FROM eventfee
RIGHT JOIN eventuser
WHERE eventuser.id='$id'

mcibor

9:40 am on Jun 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would do it so:

"SELECT event, fee, user FROM events, fees, users WHERE user='$user' AND events.user_id = users.id AND events.fee_id = fees.id OR events.fee_id IS NULL ORDER BY event";

I'm not sure if this will work, but it's worth a try
Michal Cibor