LEFT JOIN not working |
William Anthony |
2007-06-22 19:30:49 |
select ckod.fkode_ac as CustID, ckod.fproduk as Product, ckod.fsls as Sales,
ifnull(targtoko.qty,0) as Qty, ifnull(targtoko.amt,0) as Amt
from "cpu-sls/cpu-mf/cuskod.cpu" as ckod LEFT JOIN "cpu-sls/targ_02.cpu" as targtoko
on targtoko.fkode_prd = ckod.fproduk and
targtoko.fkode_sls = ckod.fsls and
targtoko.fkode_ac = ckod.fkode_ac
where targtoko.annual =? and ckod.fsls =? and ckod.fproduk =?;
This query theoretically should return ALL CustID for specified Product and Sales.Qty, Amt returned if there are exists in targtoko table. But in my result, no rows returned.
|
Re:LEFT JOIN not working |
William Anthony |
2007-06-22 19:46:52 |
Note that above situation occur, when there are no rows in the targtoko table that match the WHERE condition.
I tried adding some rows in targtoko table that match the WHERE condition, the result mimics as I'm using INNER JOIN not LEFT JOIN.
|
Re:Re:LEFT JOIN not working |
HXTT Support |
2007-06-22 20:35:44 |
Checked.
>where targtoko.annual =?
Because you use that condition in WHERE clause, wich will result HXTT DBF to convert LEFT JOIN into INNER JOIN. Please remove that condition and try again.
|
Re:Re:Re:LEFT JOIN not working |
William Anthony |
2007-06-22 20:54:54 |
It has result now, but only partially.
The real result is 30 row. If I remove targtoko.annual =? from where clause, it only return the first 5 row.
|
Re:Re:Re:Re:LEFT JOIN not working |
HXTT Support |
2007-06-22 21:07:51 |
Try:
select ckod.fkode_ac as CustID, ckod.fproduk as Product, ckod.fsls as Sales from "cpu-sls/cpu-mf/cuskod.cpu" as ckod
where ckod.fsls =? and ckod.fproduk =?;
to see whether you can get 30 rows.
|
Re:Re:Re:Re:Re:LEFT JOIN not working |
William Anthony |
2007-06-22 21:31:04 |
Yes, completely 30 rows.
|
Re:Re:Re:Re:Re:Re:LEFT JOIN not working |
HXTT Support |
2007-06-23 04:54:14 |
Failed to recure your issue. If possible, you can zip and send your test sample to webmaster@hxtt.com
|
Re:Re:Re:Re:Re:Re:Re:LEFT JOIN not working |
William Anthony |
2007-06-24 18:51:31 |
I already sent it to you, please check it. Thanks
|
Re:Re:Re:Re:Re:Re:Re:Re:LEFT JOIN not working |
HXTT Support |
2007-06-24 19:05:17 |
Passed test. jdbc:dbf:/d:/test/lib/?DefaultExtension=CPU;DefaultNTXExtension=CPX
select ckod.fkode_ac as CustID, ckod.fproduk as Product, ckod.fsls as Sales, ifnull(targtoko.qty,0) as Qty, ifnull(targtoko.amt,0) as Amt from "cpu-sls/cpu-mf/cuskod.cpu" as ckod LEFT JOIN "cpu-sls/targ_02.cpu" as targtoko on targtoko.fkode_prd = ckod.fproduk and targtoko.fkode_sls = ckod.fsls and targtoko.fkode_ac = ckod.fkode_ac where ckod.fsls ='DK1' and ckod.fproduk ='01-OS' ;
will return 30 rows.
|
Re:Re:Re:Re:Re:Re:Re:Re:LEFT JOIN not working |
William Anthony |
2007-06-24 19:38:51 |
It's worked, but only if the parameter values is written with the SQL statement like your example, when I changed it to "ckod.fsls =? and ckod.fproduk =?" and using setObject function it will return to 5 rows.
Have you test it that way?
|
Re:Re:Re:Re:Re:Re:Re:Re:LEFT JOIN not working |
HXTT Support |
2007-06-24 19:57:09 |
Passed test too.
String sql;
sql="select ckod.fkode_ac as CustID, ckod.fproduk as Product, ckod.fsls as Sales, ifnull(targtoko.qty,0) as Qty, ifnull(targtoko.amt,0) as Amt from \"cpu-sls/cpu-mf/cuskod.cpu\" as ckod LEFT JOIN \"cpu-sls/targ_02.cpu\" as targtoko on targtoko.fkode_prd = ckod.fproduk and targtoko.fkode_sls = ckod.fsls and targtoko.fkode_ac = ckod.fkode_ac where ckod.fsls =? and ckod.fproduk =? ";
pstmt = con.prepareStatement(sql);
ParameterMetaData pmd=pstmt.getParameterMetaData();
for (int j = 1; j <= pmd.getParameterCount(); j++){
System.out.println(pmd.getParameterTypeName(j)
+ " "
+pmd.getParameterClassName(j)
);
}
resultSetMetaData = pstmt.getMetaData();
iNumCols = resultSetMetaData.getColumnCount();
for (int j = 1; j <= iNumCols; j++)
System.out.print(resultSetMetaData.getColumnLabel(j) + " ");
System.out.println();
pstmt.setObject(1,"DK1");
pstmt.setObject(2,"01-OS");
// pstmt.setString(1,"DK1");
// pstmt.setString(2,"01-OS");
rs = pstmt.executeQuery();
int count=0;
while (rs.next()) {
for (int j = 1; j <= iNumCols; j++) {
colval = rs.getObject(j) + "";
System.out.print(colval + " ");
}
System.out.println();
count++;
}
System.out.print("count: "+count);
rs.close();
pstmt.close();
|
Re:Re:Re:Re:Re:Re:Re:Re:LEFT JOIN not working |
William Anthony |
2007-06-24 22:06:48 |
I checked my code again and again, but still got nothing unusual. But it's OK, Thanks to your quick support, I will try another approach.
|