简体   繁体   English

MySQLIntegrityConstraintViolationException:where子句中的列“ adno”不明确

[英]MySQLIntegrityConstraintViolationException: Column 'adno' in where clause is ambiguous

I want to get the data from two tables studentinfo ans studentmarks . 我想从两个表studentinfostudentmarks获取数据。

I use Join s with where clause but it will show: 我将Join与where子句一起使用,但它将显示:

ConstraintViolationException: Column 'adno' in where clause is ambiguous

Here is my code snippet 这是我的代码片段

String adno = jTextField10.getText();

String s = "Select si.n,
                   si.class,
                   sm.acc,
                   sm.bst,
                   sm.eco from si Left Join sm 
                   ON si.adno = sm.adno 

                   where adno ='" + adno + "';";

You didn't tell which adno column should be used WHERE clause. 您没有告诉应该在WHERE子句中使用哪个adno列。

Substitute where adno with where studentinfo.adno 替补where adnowhere studentinfo.adno

A good programmer, write pieces of code that are, Conventional, Readable, Scalable, Commented and Indented. 一个好的程序员,编写常规,可读,可伸缩,注释和缩进的代码。

In your case, do this,(mainly use aliases , and yes si.adno solves it) 在您的情况下,请执行此操作(主要使用aliases ,是的si.adno可以解决此问题)

SELECT si.name,
       si.class,
       sm.acc,
       sm.bst,
       sm.eco 
FROM studentinfo si 
LEFT JOIN studentmarks sm 
ON si.adno = sm.adno 
WHERE si.adno ='" + adno + " //qualifying the where condition

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM