views:

45

answers:

3

Hi!

I'm trying to join some tables together in MySQL, but I seem to get an error saying: #1066 - Not unique table/alias: 'calendar_jobs'

I really want it to select everything from the cal_events, the 2 user bits and just the destination col from the jobs table, but become "null" if there arn't any job. A right join seemed to fit the bill but doesn't work! Can anyone help!?

UPDATE:

Thanks for the help on the previous query, I'm now up to this:

SELECT calendar_events.* , calendar_users.doctorOrNurse, calendar_users.passportName, calendar_jobs.destination
FROM `calendar_events` , `calendar_users`
RIGHT JOIN calendar_jobs ON calendar_events.jobID = calendar_jobs.jobID
WHERE `start` >= 0
AND calendar_users.userID = calendar_events.userID;

But am now getting an error saying: #1054 - Unknown column 'calendar_events.jobID' in 'on clause'

What is it this time!?

Thanks again!

A: 

You have calendar_jobs listed twice in your query.

Once on the second line and once on the RIGHT JOIN statement.

Barry
AhhH! Thanks for that... however, i'm now getting: Unknown column 'calendar_events.jobID' in 'on clause'Whats that all about!? It's defiantly there!
Andy Barlow
Why don't you run `mysql > DESC calendar_events; ` to double check that the column is actually there.
Barry
Hiya, done that... all seems fine to me! Its certainly there!
Andy Barlow
Can you post the results?
Barry
+2  A: 

You shouldn't use calendar_jobs in the FROM clause, because you've already specified it in the JOIN. Try this:

SELECT calendar_events.* , calendar_users.doctorOrNurse, calendar_users.passportName, calendar_jobs.destination
FROM `calendar_events` , `calendar_users`
RIGHT JOIN calendar_jobs ON calendar_events.jobID = calendar_jobs.jobID
WHERE `start` >=0
AND calendar_users.userID = calendar_events.userID

Answer for update:

All evidence seems to indicate that the column doesn't exist in that table :).

Try this:

SELECT calendar_events.* , calendar_users.doctorOrNurse, calendar_users.passportName, calendar_jobs.destination
FROM `calendar_users`, `calendar_events`
RIGHT JOIN calendar_jobs ON calendar_events.jobID = calendar_jobs.jobID
WHERE `start` >=0
AND calendar_users.userID = calendar_events.userID

The order of the tables in the FROM has been switched, because you join events with jobs.

Alex Ciminian
It's defiantly there! I can see it from here, even copies and pasted to be sure... Is it because of the "where" statement below?
Andy Barlow
See if my edit works :). Cheers!
Alex Ciminian
+1  A: 

Run this: show create table calendar_events; , and post the results here.

We need to see the table structure to answer your second question.

ceteras