C# mysql连接查询重复返回数据
我想在c windows窗体中使用join query从mysql数据库检索数据,但它会重复给我100次数据。 这是我的密码。请帮忙C# mysql连接查询重复返回数据,c#,mysql,C#,Mysql,我想在c windows窗体中使用join query从mysql数据库检索数据,但它会重复给我100次数据。 这是我的密码。请帮忙 private void button2_Click(object sender, EventArgs e) { if (comboBox1.SelectedIndex < 0 || comboBox2.SelectedIndex < 0) { Messag
private void button2_Click(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex < 0 || comboBox2.SelectedIndex < 0)
{
MessageBox.Show("Please select the Class and group");
}
else
{
table = dbOperation.select("student.admission_no, student.studid, student.name from student inner join " +
"studentinclass on studentinclass.studentid = student.studid inner join " +
"class on studentinclass.classid = " + comboBox1.SelectedValue + " inner join " +
"`group` on studentinclass.groupid = " + comboBox2.SelectedValue + " inner join " +
"section on studentinclass.sid = " + comboBox3.SelectedValue);
listView1.Items.Clear();
foreach (DataRow row in table.Rows)
{
listView1.Items.Add(row[0].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(row[1].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add(row[2].ToString());
listView1.Items[listView1.Items.Count - 1].SubItems.Add("P");
}
}
}
这是输出
学生ID是这两个表中的主键吗?您需要一个子查询进行比较 要删除完整的select语句
"student.admission_no, student.studid, student.name from student " +
"where student.studid in ( select studentinclass.studentid from studentinclass " +
"inner join class on studentinclass.classid = " + comboBox1.SelectedValue + " " +
"inner join `group` on studentinclass.groupid = " + comboBox2.SelectedValue + " " +
"inner join section on studentinclass.sid = " + comboBox3.SelectedValue +")"
您期望的输出是什么?顺便说一句,在Select关键字后添加“DISTINCT”将帮助您消除所有重复行。dbOperation是什么类型?它是连接数据库的类的对象。只是我不希望重复。学生ID是否唯一标识两个表中的每个记录?