Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to update one table by joining two table in mysql?
    primarykey
    data
    text
    <p>I got two tables one is for regcourses and another is named coursegroups.</p> <p><strong>coursegroups table</strong></p> <pre><code>CREATE TABLE coursesgroup ( csgrec int(11) unsigned NOT NULL auto_increment, courseID int(11) default NULL, classID int(11) default NULL, studgroup varchar(20) default NULL, studnum int(11) default NULL, PRIMARY KEY (csgrec) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; </code></pre> <p><em><strong>regcourses table:</em></strong></p> <pre><code>CREATE TABLE regcourses ( regrec int(11) unsigned NOT NULL auto_increment, regsemrec int(11) default NULL, regstudID int(11) default NULL, regcourseID int(11) default NULL, regstatus int(11) default '0', yearsem int(11) default '2012', monthsem1 int(11) default '3', classID int(11) default '1', PRIMARY KEY (regrec) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; </code></pre> <p><strong>Insert statement:</strong></p> <pre><code>INSERT INTO coursesgroup VALUES ('2', '20', '1', 'BBA1009A1', '11'); INSERT INTO coursesgroup VALUES ('3', '20', '1', 'BBA1009B1', '4'); INSERT INTO regcourses VALUES ('2', '1', '98', '47', '0', '2012', '3', '1'); INSERT INTO regcourses VALUES ('4', '1', '98', '101', '0', '2012', '3', '1'); </code></pre> <p>I want to update the regstatus field of regcourses table to "2" for a specific value of csgrec column in coursesgroup table. So my update code is:</p> <pre><code>UPDATE regcourses JOIN coursesgroup ON regcourses.regcourseID = coursesgroup.courseID Set regcourses.regstatus =2 WHERE coursesgroup.csgrec=3 </code></pre> <p>but my query is affecting so many rows instead of one row. Because I want to change the csgrec=3 only and my query affects all of the lines which matches with <code>regcourses.regcourseID = coursesgroup.courseID condition</code>. Please help me on this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload