mysql multiple table update problem
07-09-08, 04:13 AM
Newbie Coder
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
mysql multiple table update problem
hi all..
i need help to solve my problem..i have a few table to update in the same time..
but dont know how to write the correct sql statement..
07-09-08, 04:25 AM
Junior Code Guru
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
http://forums.mysql.com/read.php?20,85813,85813
first reply to that post gives a example
sql Code:
UPDATE a
INNER JOIN b USING ( id)
SET a.firstname='Pekka' , a.lastname='Kuronen' ,
b.companyname='Suomi Oy' ,companyaddress='Mannerheimtie 123, Helsinki Suomi'
WHERE a.id=1 ;
07-09-08, 04:32 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Thread moved to Database section...
07-09-08, 04:59 AM
Newbie Coder
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
thanks <?Wille?>..
i will try it out..
07-09-08, 05:28 AM
Newbie Coder
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:
$result = mysql_query ( "UPDATE
project1 p1, panel_detail pd, pic p, discreapancy d
set p1.project_id=' $ncr [ 0 ] ', p1.Project_Name=' $ncr [ 1 ] ', p1.Part_No=' $ncr3 ',
p1.Description=' $ncr4 ', p1.Project_Date=' $date ',
p.Staff_id=' $staffid ', p.stamp_no=' $stampno ', p.Originator=' $or ', p.Location_pic=' $location ',
pd.Discreapancy_id=' $ncr ', pd.Oper_No=' $operno ', pd.Drawing_No=' $drawingno ', pd.Rev=' $rev ',
pd.Date_Cure=' $date1 ', pd.GRR_Batch=' $grrno ', pd.S_No=' $sn ', pd.Jig=' $jigno ',
pd.Batch_Quantity=' $batchqtty ', pd.JO_No=' $jono ',
d.Quantity_Discrepant=' $qttydiscrpnt ', d.Discreapancy_detail=' $discreapancy ',
d.Others=' $notes ', d.Defect_Code=' $DCode '
WHERE NCR_No=' $ncrno '" );
i already try it..but it doesnt update inside my database..
sori i'm very weak in programing..
07-09-08, 05:35 AM
Community Leader
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:
$query = "UPDATE project1 p1, panel_detail pd, pic p, discreapancy d set p1.project_id=' $ncr [ 0 ] ', p1.Project_Name=' $ncr [ 1 ] ', p1.Part_No=' $ncr3 ', p1.Description=' $ncr4 ', p1.Project_Date=' $date ', p.Staff_id=' $staffid ', p.stamp_no=' $stampno ', p.Originator=' $or ', p.Location_pic=' $location ', pd.Discreapancy_id=' $ncr ', pd.Oper_No=' $operno ', pd.Drawing_No=' $drawingno ', pd.Rev=' $rev ', pd.Date_Cure=' $date1 ', pd.GRR_Batch=' $grrno ', pd.S_No=' $sn ', pd.Jig=' $jigno ', pd.Batch_Quantity=' $batchqtty ', pd.JO_No=' $jono ', d.Quantity_Discrepant=' $qttydiscrpnt ', d.Discreapancy_detail=' $discreapancy ', d.Others=' $notes ', d.Defect_Code=' $DCode ' WHERE NCR_No=' $ncrno '" ; if (! $result = mysql_query ( $query )) { echo '<pre>' ; printf ( "MySQL error: %s\n" , mysql_error ()); printf ( "Query: %s" , $query ); exit( '</pre>' ); }
Do it this way, and let MySQL tell you what the problem is. Also make sure the query string contains the expected values.
Last edited by Nico; 07-09-08 at 05:44 AM .
07-09-08, 08:49 PM
Newbie Coder
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
i already try it but still have error on it.it tell that
Quote:
MySQL error: Column 'NCR_No' in where clause is ambiguous
07-10-08, 02:44 AM
Newbie Coder
Join Date: Jun 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by
ordique
MySQL error: Column 'NCR_No' in where clause is ambiguous
I believe this indicates that the field 'NCR_No' exists in more than one of the specified tables. You need to specify which table must be used in matching the where clause, or if this field must match in all tables which contain it, you have to specify that.
Like this
or this
07-10-08, 02:55 AM
Newbie Coder
Join Date: Jun 2008
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
You are right dustin56..i have NCR_No in every table that i have b'cause it is foreign key.thank you for the information..
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off