Karl_Schuhmann
Karl_Schuhmann

Reputation: 1332

PGSQL Error Code 42703 column does not exist

I have a database in postgreSQL. I want to read some data from there, but I get an error (column anganridref does not exist) when I execute my command.

Here is my NpgsqlCommand:

cmd.CommandText = "select * from angebot,angebotstatus,anrede where anrid=anganridref and anstaid=anganstaidref";

and my 3 tables

http://img4.fotos-hochladen.net/uploads/unbenanntg4059ucm6j.png

the names of my columns are rights. So I don't understand why that error comes. Someone can explain me why it does crash? Its not the problem of large and lowercase.

Upvotes: 2

Views: 24892

Answers (1)

user330315
user330315

Reputation:

You are not prefixing your column names in the where clause:

select * 
from angebot,
     angebotstatus,
     anrede 
where anrid = anganridref   <-- missing tablenames for the columns
  and anstaid = anganstaidre

It's also recommended to use an explicit JOIN instead of the old SQL 89 implicit join syntax:

select * 
from angebot 
   join angebotstatus on angebot.aaaa = angebotstatus.bbbb
   join anrede on angebot.aaaa = anrede.bbbb

Upvotes: 2

Related Questions