[英]how to get result from table where there are no values only after joining two tables
Statement st=conn.createStatement();
String sql="SELECT a.ID,a.A_TEXT,a.B_TEXT,a.C,a.D_TO_E,a.F_TEXT,a.G,a.INTIME,b.EXIT_TIME FROM tm_A a LEFT JOIN tm_B b ON a.ID=b.ID WHERE EXIT_TIME=''";
ResultSet rs=st.executeQuery(sql);
while(rs.next())
{
arls.add(rs.getString("ID"));
arls.add(rs.getString("A_TEXT"));
arls.add(rs.getString("B_TEXT"));
arls.add(rs.getString("C"));
arls.add(rs.getString("D_TO_E"));
arls.add(rs.getString("F_TEXT"));
arls.add(rs.getString("G"));
arls.add(rs.getString("INTIME"));
arls.add(rs.getString("EXIT_TIME"));
}
I have above code in that i want to retreive values from two tables where EXIT_TIME ='null' but i am getting nothing after executing though there are value in table tm_A but if i remove where clause then i am getting result and but under EXIT_TIME it displays 'null' and where there are values that are displaying 我有上面的代码,我想从两个表中检索值,其中EXIT_TIME ='null'但是我执行后没有得到任何东西虽然表tm_A中有值但是如果我删除where子句然后我得到结果但是在EXIT_TIME下它显示'null'并显示正在显示的值
If you want to select a result where a column is null
you have to use the is
operator: 如果要选择
null
的结果,则必须使用is
运算符:
SELECT a.ID,a.A_TEXT,a.B_TEXT,a.C,a.D_TO_E,a.F_TEXT,a.G,a.INTIME,b.EXIT_TIME
FROM tm_A a
LEFT JOIN tm_B b ON a.ID=b.ID
WHERE EXIT_TIME is null
Comparison with null
will always result to unknown
. 与
null
比较总是会导致unknown
。 That is why you need the is
operator instead of =
这就是为什么你需要
is
运算符而不是=
using EXIT_TIME=''
would compare EXIT_TIME
to an empty string but not null
使用
EXIT_TIME=''
将EXIT_TIME
与空字符串进行比较,但不是null
If you want all records that are not null
in EXIT_TIME
you can use 如果您想要在
EXIT_TIME
中使用非 null
所有记录,则可以使用
WHERE EXIT_TIME is not null
You can use case
to avoid null
in your textboxes: 您可以使用
case
来避免文本框中的null
:
SELECT a.ID,
a.A_TEXT,
a.B_TEXT,
a.C,
a.D_TO_E,
a.F_TEXT,
a.G,
a.INTIME,
case when b.EXIT_TIME is null
then 'NA'
else b.EXIT_TIME
end as EXIT_TIME
FROM tm_A a
LEFT JOIN tm_B b ON a.ID=b.ID
Just say 说啊
WHERE EXIT_TIME is null
instead of 代替
WHERE EXIT_TIME=''
Hope it helps you... 希望它能帮到你......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.