MySQL Update

I have  2 table

tblDDAI
tblCards

both have identical columns but data is missing from tblDDAI that is in tblCards.

I have identified the records and now want to run an update query.

I am trying below

Update tblDDAI
set tblDDAI.Photo = tblcards.Photo
where tblcards.ddaiid = '15'

Open in new window


I am getting an error

Error Code: 1054. Unknown column 'tblcards.ddaiid' in 'where clause'

The table is there with the correct column name
BrogrimInformation Systems Development ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dsackerContract ERP Admin/ConsultantCommented:
You need to join your tables. I assume they join by ddaiid. If not, you'll need to join them by the appropriate key.

Update tblDDAI
set tblDDAI.Photo = tblcards.Photo
from tblcards
where tblcards.ddaiid = tblDDAI.ddaiid
and tblcards.ddaiid = '15'

Open in new window

0
BrogrimInformation Systems Development ManagerAuthor Commented:
Error Code: 1064. 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 'from tblcards where tblcards.ddaiid = tblDDAI.ddaiid and tblcards.ddaiid = '15'' at line 3
0
dsackerContract ERP Admin/ConsultantCommented:
Ah, sorry. Coded it for SQL Server:

Update tblDDAI
set tblDDAI.Photo = (SELECT tblcards.Photo from tblcards
where tblcards.ddaiid = tblDDAI.ddaiid
and tblcards.ddaiid = '15')

Open in new window

0
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

BrogrimInformation Systems Development ManagerAuthor Commented:
Is this going to update all the photos instaed of just id 15

It is running for about 5 minutes now
0
dsackerContract ERP Admin/ConsultantCommented:
It probably will. Just wanted to be sure it was at least working for you.

This should fine-tune that issue:

Update tblDDAI
set tblDDAI.Photo = (SELECT tblcards.Photo from tblcards
where tblcards.ddaiid = tblDDAI.ddaiid)
where tblDDAI.ddaiid = '15'

Open in new window

Of course, if you want to update them all, just take the final "WHERE" off.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BrogrimInformation Systems Development ManagerAuthor Commented:
apoligies, I thought I assigned the points
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.