Thanks friend, INSERT INTO .... SELECT .... seems to be the wrong
option in this situation, it doesn't work. But UPDATE option as
suggested by you did the trick. Thank you once again. I have advanced
one more step towards learning sql.



--- In [email protected], "Satish Vellanki" <[EMAIL PROTECTED]>
wrote:
>
> OK here is what I understand:
> 1. You have some "students" and they have corresponding "classes"
> So all you wanna do is update "students" with appropriate "class" values
>
> UPDATE "students" SET "class" = (SELECT "class" FROM "classes" WHERE
> "students"."roll_no" = "classes"."roll_no")
>
> 2. If you wanna insert *all* records in "classes" into "students"
then, do
> this:
> INSERT INTO "students" ("roll_no", "class") SELECT * FROM "class"
>
> I am not sure if PostgreSQL allows inserting not all fields when using
> SELECT, please check the manual at
http://www.postgresql.org/docs/manuals/
>
> --
> Satish Vellanki
>
> On Tue, Jul 8, 2008 at 9:38 AM, Aditya <[EMAIL PROTECTED]> wrote:
>
> >
> > > For INSERT: Since "roll_no" is a primary key, your INSERT statement
> > should
> > > include "roll_no" in the inserting fields.
> >
> > Sorry for my ignorance, but how do I exactly do that?
> >
> >
> >
>

Reply via email to