Jump to content

insert and join


An7hony

Recommended Posts

I have some mysql

 

UPDATE t1 LEFT JOIN t2 ON t2.id = t1.id SET t1.col1 = newvalue WHERE t2.id IS NULL;

 

I have used the above example and it works well.

 

I Know need to join and insert. Have Tried the below

 

INSERT INTO Carer_Category_Subgroup LEFT JOIN Carer_Project_SubGroup ON Carer_Project_SubGroup.CPC_Carer = Carer_Category_Subgroup.CCatS_Carer SET Carer_Category_Subgroup.CCatS_Category = '50' WHERE Carer_Project_SubGroup.CPC_Project = '1';

 

but get:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN Carer_Project_SubGroup ON Carer_Project_SubGroup.CPC_Carer = Carer_Cat' at line 1"

 

 

Can't seem to get this to work?

Link to comment
https://forums.phpfreaks.com/topic/282417-insert-and-join/
Share on other sites

 


looking at it i'll try this:

 

You souldn't try things out, you should read about what you are doing and fix your mistake.

 

You cannot LEFT JOIN during an insert because you are creating a new record so there is no record to join yet.

 

Perhaps you should start by saying what you want to achieve, there mist be a reason why you wanted to use the JOIN?

Link to comment
https://forums.phpfreaks.com/topic/282417-insert-and-join/#findComment-1451067
Share on other sites

going to try this

 

create a new field in Carer_Project_SubGroup called CPC_CatGroup. Update all CPC_Project=1 with CPC_CatGroup=50 and then run:

insert into Carer_Category_Subgroup (CCatS_Carer)
select (50) from Carer_Project_SubGroup
where Carer_Project_SubGroup.CPC_Project=1 AND Carer_Project_SubGroup.CPC_CatGroup=50

Link to comment
https://forums.phpfreaks.com/topic/282417-insert-and-join/#findComment-1451077
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.