Thread: Two table joins

Two table joins

From
Kumar S
Date:
Hi all,

I have 3 tables like the following:

sample_table:
samp_id
samp_desc
samp_data


Experiment table:
exp_id
samp_id
exp_slot_id
exp_data1
exp_data2

exp_slot_table
exp_slot_id
exp_id
exp_slot_name


Now I want to update column samp_id in experiment
table.

I want to introduce samp_id = 3 and with a clause :
update samp_id in experiment table WHERE exp_slot_name
= 3264.dat; Here 3264.dat has exp_slot_id which is
present as a column in experiment table.

Can any one help me to get a correct update statement.
I am confused here.

My wrong SQL statement:

update experiment SET samp_id =3 WHERE (select
exp_slot_name = 4264.dat WHERE exp_slot_id =
exp_slot_name);

Thank you.
Kumar




__________________________________
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

Re: Two table joins

From
Tom Lane
Date:
Kumar S <ps_postgres@yahoo.com> writes:
> My wrong SQL statement:

> update experiment SET samp_id =3 WHERE (select
> exp_slot_name = 4264.dat WHERE exp_slot_id =
> exp_slot_name);

I think you want something like

update experiment SET samp_id = 3
WHERE exp_slot_id = (SELECT exp_slot_id FROM exp_slot_table
                     WHERE exp_slot_name = '4264.dat');

            regards, tom lane