-2

Hey I have a Problem in my SQL Statement

select Objektnr, AVG(Mieter.Miete) as "Durchschnitt Miete" from Objekt
join Wohnung on Objekt.Objektnr = Wohnung.Objektnr
join Mieter on Wohnung.Wohnungsnr=Mieter.Wohnungsnr

My Join don't work :(

Here is the Error: #1052 - Column 'Objektnr' in field list is ambiguous

pnuts
  • 58,317
  • 11
  • 87
  • 139
Tarasov
  • 3,625
  • 19
  • 68
  • 128

2 Answers2

2

The issue is that you are saying you want to select the field Objektnr, but it exists in more than one table. It's ambiguous because it doesn't know which one to pick from. You need to fully qualify your column so that it knows which one to select - and since these are the same between the two tables (due to the JOIN), the following should work:

Select   Objekt.Objektnr, 
         AVG(Mieter.Miete) as "Durchschnitt Miete" 
From     Objekt
Join     Wohnung on Objekt.Objektnr = Wohnung.Objektnr
Join     Mieter  on Wohnung.Wohnungsnr = Mieter.Wohnungsnr
Siyual
  • 16,415
  • 8
  • 44
  • 58
0

means you have same field in diferent tables

just include the table before the field

select Objekt.Objektnr, AVG(Mieter.Miete) as "Durchschnitt Miete" from Objekt
join Wohnung on Objekt.Objektnr = Wohnung.Objektnr
join Mieter on Wohnung.Wohnungsnr=Mieter.Wohnungsnr
Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118