Note that there are some explanatory texts on larger screens.

plurals
  1. POremove additional rows with mysql
    text
    copied!<p>I have a database that contains the tables.</p> <pre><code>create table student ( stu_code integer, stu_name varchar(32), primary key (stu_code) ) create table teacher ( tea_code integer not null, tea_name varchar(25), primary key (tea_code) ) create table course ( cor_code integer not null, cor_name varchar(32), salary float(32), unit integer, primary key (cor_code) ) create table term ( stu_code integer, cor_code integer, tea_code integer, grade decimal(25), year integer, ) </code></pre> <p>I've filled three tables manually.</p> <p>And term Table was generated by a Javascript code : </p> <pre><code>&lt;html&gt; &lt;body&gt; &lt;div id="rnd"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; function rnd(a,b){ return Math.floor(Math.random()*(b-a+1))+a; } for (var i=0;i&lt;600;i++) { var stu = rnd(41,49), cor = rnd(10,26), tea = rnd(81,90), year = rnd(1391,1392), grade = rnd(8,20); (year==1392)?grade = null:true; document.writeln( "insert into term (stu_code,cor_code,tea_code,grade,year) values " +"(884221" +stu+"," +"180" +cor+"," +"15120" +tea+"," +grade +"," +year +");" +"&lt;br&gt;" ); } &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>My problem is there are additional rows in term Table.</p> <p>How do I integrate/remove additional rows ?</p> <p>Is there a way to fill the table with no additional random row?</p> <p><strong>/* update : */</strong></p> <p>for example : </p> <pre><code>insert into term (s,c,t,g) values (45,16,88,16,91); insert into term (s,c,t,g) values (45,16,86,10,91); insert into term (s,c,t,g) values (45,16,87,8,91); insert into term (s,c,t,g) values (41,15,85,20,91); insert into term (s,c,t,g) values (41,15,88,17,91); </code></pre> <p>now i want to display : </p> <pre><code>insert into term (s,c,t,g) values (45,16,88,16,91); insert into term (s,c,t,g) values (41,15,85,20,91); or insert into term (s,c,t,g) values (45,16,88,16,91); insert into term (s,c,t,g) values (41,15,88,17,91); or insert into term (s,c,t,g) values (45,16,86,10,91); insert into term (s,c,t,g) values (41,15,85,20,91); or insert into term (s,c,t,g) values (45,16,86,10,91); insert into term (s,c,t,g) values (41,15,88,17,91); or insert into term (s,c,t,g) values (45,16,87,8,91); insert into term (s,c,t,g) values (41,15,85,20,91); or insert into term (s,c,t,g) values (45,16,87,8,91); insert into term (s,c,t,g) values (41,15,88,17,91); </code></pre> <p><strong>/*end update */</strong></p> <p><strong>/* update again */</strong></p> <p>I could write a code in Sql Server But this code does not work in Mysql why? What is the equivalent of this code in Mysql?</p> <pre><code>delete from term where stu_code in( select stu_code from term group by stu_code,cod_code,year having COUNT(stu_code)&gt;=2 </code></pre> <p><strong>/* end last update */</strong></p> <p>please help me to solve this !</p> <p>thanks :x</p>
 

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