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.
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 tablesclassified_jobsclassified_job_destinationsdestination_oldI 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_idLEFT 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 ambiguousPlease helpthanksJ |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2014-08-07 : 05:09:59
|
include the table name before the column name in select listJaveed Ahmed |
 |
|
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 listJaveed Ahmed
I have haven't i? |
 |
|
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 columnJaveed Ahmed |
 |
|
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' |
 |
|
ahmeds08
Aged Yak Warrior
737 Posts |
Posted - 2014-08-07 : 06:50:27
|
post your table structureJaveed Ahmed |
 |
|
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_idAlso when you join to table classified_jobs, your on statement referes same table on both right and left side. |
 |
|
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_idAlso 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! |
 |
|
|
|
|