PDA

View Full Version : can i use join in update query


o0O0o.o0O0o
05-22-2009, 01:44 AM
hi

is it possible to use join in update query or insert query , where i want to inser t some data from table B to Table A e.g


UPDATE table A , Table B ,

SET A.task_id = B.task_id

where B.category_id in (select category_id from Table C where userid = 1)


UPDATE table A , Table B ,

SET A.task_id = B.task_id

inner join Table C on (B.category_id = C.category_id and C.user_id = 1)


Table C contains all user categories
Table B contains all tasks for all categories
Table A contains all user tasks which are in all user categories

Old Pedant
05-22-2009, 05:39 AM
You have an extra comma in both of those queries, after "Table B".

But in *neither* of those queries are you joining tables A and B, so you will end up changing *ALL* the records in table A. Surely that's not what you want??

So I don't think any of that code makes sense. Try to explain what is ACTUALLY in the 3 tables and what you want to ACTUALLY happen.

o0O0o.o0O0o
05-22-2009, 06:09 AM
Basically i want to make a trigger so that if any record is inserted in
Table C then for every record_id , i find all the tasks associated with that id from Table B and then insert all those task_ids , with category_id in Table A.

Is it posiible or wise to do it that way.
or i was thinking of making a procedure

or i should put that in application rather dtabase

o0O0o.o0O0o
05-22-2009, 07:23 AM
I got the trigger working!! Yippy i don't knew so many things can be done in mysql only.
Much of my application logic is reduced