Are you trying to UPDATE or INSERT?
The query you have written works with UPDATE.
For INSERT: Since "roll_no" is a primary key, your INSERT statement should
include "roll_no" in the inserting fields.
Let us know if that doesn't answer your question
-- 
Satish Vellanki

On Tue, Jul 8, 2008 at 5:21 AM, Aditya <[EMAIL PROTECTED]> wrote:

>   Hi,
> I am new to postgresql. I have a small problem. I have two tables 1)
> students and 2) classes with the following structure -
>
> Students -
> 1) roll_no
> 2) name
> 3) class
>
> and Classes -
> 1) roll_no
> 2) class
>
> with roll_no being primary key in both the tables. Now I want to
> insert the data from the class field in 'classes' into the class field
> of 'students'. I tried the following
> __________________________________________________________
>
> INSERT INTO students (class)
> SELECT class FROM classes WHERE students.roll_no = classes.roll_no;
> __________________________________________________________
>
> I get the following error -
>
> __________________________________________________________
> ERROR: invalid reference to FROM-clause entry for table "students"
> LINE 3: WHERE students.roll_no = classes.roll_no
> ^
> HINT: There is an entry for table "students", but it cannot be
> referenced from this part of the query.
> __________________________________________________________
>
> Any suggestions?
>
> Thanking you,
> Aditya Pratap V.
>
>  

Reply via email to