Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 #1052 Column 'destination_id' is ambiguous

Author  Topic 

jarv
Posting Yak Master

131 Posts

Posted - 2014-08-07 : 05:07:11
hi,

I am trying to get a country name out of my database:

I have 3 tables

classified_jobs
classified_job_destinations
destination_old

I am trying to join the 3 as follows:


select DISTINCT destination_id, classified_job_id from classified_job_destinations inner join classified_jobs
on classified_jobs.classified_jobs_id = classified_jobs.classified_job_id
LEFT JOIN destinations_old
ON destinations_old.destination_id = classified_job_destinations.destination_id WHERE classified_jobs.classified_jobs_id = '438'


but I am getting the error: #1052 - Column 'destination_id' in field list is ambiguous

Please help

thanks

J

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-08-07 : 05:09:59
include the table name before the column name in select list

Javeed Ahmed
Go to Top of Page

jarv
Posting Yak Master

131 Posts

Posted - 2014-08-07 : 05:33:30
quote:
Originally posted by ahmeds08

include the table name before the column name in select list

Javeed Ahmed



I have haven't i?
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-08-07 : 05:48:19
in the select add the table name from which it is being selected before destinationid column

Javeed Ahmed
Go to Top of Page

jarv
Posting Yak Master

131 Posts

Posted - 2014-08-07 : 06:39:47
ok, I have changed it to this

SELECT DISTINCT classified_jobs.destination_id, classified_jobs.classified_job_id, classified_job_destinations.classified_job_id FROM classified_job_destinations INNER JOIN classified_jobs on classified_jobs.classified_jobs_id = classified_job_destinations.classified_job_id LEFT JOIN destinations_old ON classified_job_destinations.destination_id = destinations_old.destination_id WHERE classified_jobs.classified_job_id = '438'


Now I am getting: #1054 - Unknown column 'classified_jobs.classified_jobs_id' in 'on clause'
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2014-08-07 : 06:50:27
post your table structure

Javeed Ahmed
Go to Top of Page

bitsmed
Aged Yak Warrior

545 Posts

Posted - 2014-08-07 : 07:30:26
Could it be a typo?
You reference both classified_jobs_id and classified_job_id

Also when you join to table classified_jobs, your on statement referes same table on both right and left side.
Go to Top of Page

jarv
Posting Yak Master

131 Posts

Posted - 2014-08-07 : 10:02:25
quote:
Originally posted by bitsmed

Could it be a typo?
You reference both classified_jobs_id and classified_job_id

Also when you join to table classified_jobs, your on statement referes same table on both right and left side.



I've done it thank you!
Go to Top of Page
   

- Advertisement -