Please help: Multi-part identifier could not be bound - mysql

I know there are quite a few posts regarding this topic, but I'm really stumped as to why my code isn't working. I simply have two tables and am trying to update a value in one table with information from the other based on a where statement. I have pretty much used this same code in other instance to do this without any issue, so I'm not sure why I'm getting an error here in this case. If anyone could offer up any assistance, I'd greatly appreciate it.
Code:
update [DB].[dbo].[table1]
set [DB].[dbo].[table1].[variable_name] = [DB].[dbo].[table2].[variable_name]
where ([DB].[dbo].[table1].[Year] = [DB].[dbo].[table2].[Year] and
[DB].[dbo].[table1].[Id] = [DB].[dbo].[table2].[Id]);
Variable_Name is text in both tables and Year/Id are both Int.

You need to join table2 in the update statement.
UPDATE t1
SET [table1].[variabe_name] = [table2].[variable_name]
FROM [table1] t1
INNER JOIN [table2]
ON [table1].[variable_name] = [table2].[variable_name]
WHERE ([table1].[Year] = [table2].[Year] AND [table1].[Id] = [table2].[Id]);

Related

DELETE FROM table WHERE condition is met in other table

I have this SQL query that has been working great. I would like to have something similar that would delete a line from PRC_FIX when the column DESCR in IM_ITEM begins with Clearance instead of where ITEM_VEND_NO = 'GAMES WORK'.
DELETE `PRC_FIX` FROM `PRC_FIX`
INNER JOIN `IM_ITEM` ON `IM_ITEM`.`ITEM_NO` = `PRC_FIX`.`ITEM_NO`
AND `IM_ITEM`.`ITEM_VEND_NO` = 'GAMES WORK'
Thanks for your help.
Edit: This was marked as a possible duplicate. I don't know that looking at the suggested duplicate would have helped me because I wouldn't have known how to implement it in this scenario involving 2 tables, but I'm willing to admit that might be my fault due to me being new to SQL.
You can use
DELETE PRC_FIX
FROM PRC_FIX
INNER JOIN IM_ITEM
ON IM_ITEM.ITEM_NO = PRC_FIX.ITEM_NO
WHERE UPPER(IM_ITEM.DESCR) LIKE 'CLEARANCE%';
You need to use the wildcard %.
in order to match with this string with different string which begins with "Clearance" you need to use "Clearance%".
Look here: SQL like search string starts with
You're fixed code:
DELETE `PRC_FIX` FROM `PRC_FIX`
INNER JOIN `IM_ITEM` ON `IM_ITEM`.`ITEM_NO` = `PRC_FIX`.`ITEM_NO`
AND IM_ITEM.DESCR LIKE 'Clearance%'
DETELE FROM PRC_FIX WHERE ITEM_NO IN (SELECT ITEM_NO FROM IM_ITEM WHERE ITEM_VEND_NO` = 'GAMES WORK')

Ambiguous JOIN variable - in initial FROM... really?

EDIT OK so the main problem here was initial column1 FROM table1 with the join. Even that column1 has to be fully defined as table1.column1 even tho it is next to the FROM which seems at best odd to me. But I guess this is a newb error and I hope other newbs will find this useful.
//========================================================================
Have used simple joins before without problems. I thought the table.column format was unambiguous.
Warning is:
Integrity constraint violation: 1052 Column 'transmissionProgramID'
in field list is ambiguous'
The SQL is:
SELECT transmissionProgramID FROM transmissionProgramOwner
JOIN transmissionProgram on transmissionProgram.transmissionProgramID
= transmissionProgramOwner.transmissionProgramID WHERE
ownerType = '$ownerType' AND ownerID = '$ownerID' ORDER BY startDate
The two table transmissionProgramOwner and transmissionProgram both have fields called transmissionProgramID. I just cannot see how the table.column leaves anything ambiguous.
Sure it is something simple but I cannot see it. And I apologize for the long variable names but helps me keep things clear.
Additional info: Both transmissionProgramID are set to unique in both tables. I have tried every flaovor of JOIN but I think a simple join is allowed which just returns all records that match... In any case have tried every type of join just to make sure.
Friend try this
SELECT t1.transmissionProgramID FROM transmissionProgramOwner t1
JOIN transmissionProgram t2 on t2.transmissionProgramID
= t1.transmissionProgramID WHERE
t1.ownerType = '$ownerType' AND t1.ownerID = '$ownerID' ORDER BY t1.startDate;
change to
SELECT transmissionProgram.transmissionProgramID FROM
transmissionProgramOwner JOIN transmissionProgram on
'transmissionProgram.transmissionProgramID'
= 'transmissionProgramOwner.transmissionProgramID' WHERE ownerType = '$ownerType' AND ownerID = '$ownerID' ORDER BY startDate

Wrong syntax in a SQL query

I'm trying to write a query that takes a point, given to a player in a match event, multiply it by another column and then by 3, and then copy the result in the players table where the player already exists.
There is an error but I can't find what's wrong. Can you help me, please, with solving this issue?
UPDATE
j7yh8_bl_match_events,
j7yh8_bl_players
SET
j7yh8_bl_players.player_points = SELECT COUNT(j7yh8_bl_match_events.e_id) * j7yh8_bl_match_events.ecount * 3,
WHERE
j7yh8_bl_match_events.player_id = j7yh8_bl_players.id AND j7yh8_bl_match_events.e_id = 5;
Any help will be appreciated.
Thank you.
In MySQL, you can use a join with update. Any aggregation functions, though, have to be in subqueries.
I'm not 100% sure that the expression is for calculating points. It seems that something like this solves your problem:
UPDATE j7yh8_bl_players p LEFT JOIN
(SELECT me.player_id, SUM(me.ecount) * 3 as points
FROM j7yh8_bl_match_events me
WHERE me.e_id = 5
GROUP BY me.player_id
) me
ON me.player_id = p.id
SET p.player_points = me.points

Error 1054: Unknown column in field list and where clause

I am missing something here, not sure what. please help me.
I am trying to copy the data in vs_smelter_temporary into vs_smelter_ext with a where clause
use test;
Update vs_smelter_ext
SET vs_smelter_ext.Certification_Status = vs_smelter_temporary.Certification_Status
where
vs_smelter_ext.Smelter_Id = vs_smelter_temporary.Smelter_Id
;
You need to join to the temporary table:
UPDATE vs_smelter_ext
JOIN vs_smelter_temporary ON vs_smelter_ext.Smelter_Id = vs_smelter_temporary.Smelter_Id
SET vs_smelter_ext.Certification_Status = vs_smelter_temporary.Certification_Status;

MySQL update from one table to another with condition not working?

I have tried a solution that seems to work for someone else on this question:
Update table a from table b where (conditions)
I can not seem to get it working, MySql gives me a syntax error.
I have two tables, and I need to update a column in one table to the value of another column where an id matches in both tables.
UPDATE video_data SET video_data.date_timestamp = video.date_timestamp FROM video_data JOIN video ON video_data.video_id = video.video_id
I am not sure what the issue is with my syntax. I am quite tired and maybe it is just my eyes playing with me. Thanks for the help!
Try this syntax out:
UPDATE video_data, video
SET video_data.date_timestamp = video.date_timestamp
WHERE video_data.video_id = video.video_id
UPDATE video_data, video SET video_data.date_timestamp = video.date_timestamp
WHERE video_data.video_id = video.video_id
Try this:
UPDATE video_data SET date_timestamp = (SELECT video.date_timestamp FROM video WHERE video.video_id = video_data.video_id)
Although the error in your actual query is simply that you missed a "SELECT"
UPDATE video_data SET video_data.date_timestamp = SELECT video.date_timestamp FROM video_data JOIN video ON video_data.video_id = video.video_id
But I don't think it is what you want it to be.