|
View previous topic :: View next topic
|
| Author |
Message |
Krishnadeva Reddy
New User

Joined: 14 Nov 2007 Posts: 40 Location: Chennai
|
|
|
|
Hi,
I'm trying to get all rows from two tables by joining.
When there is no corresponding row found in TABLEB, I'm trying to get blanks in the output but my query is not giving desired results
Please advise.
TABLEA - sample data and this table has more rows than this
| Code: |
---------+---------+---------+---------+---------+---------+-----
B_OFF# ID_USER SVC_FRM_DT SVC_THRU_DT P_ID
---------+---------+---------+---------+---------+---------+------
300000610 761001 2011-06-01 2011-06-01 0
300000620 761002 2011-06-01 2011-06-01 351001
310544110 760996 2010-10-19 2010-10-19 352001
310544220 760997 2010-10-19 2010-10-19 451003
310544330 760998 2010-10-19 2010-10-19 0
|
TABLEB - sample data and this table has more rows than this
| Code: |
---------+---------+---------+---------
P_ID CHK_AMT ISS_DTE CHK_#
---------+---------+---------+---------
351001 50.00 2011-06-01 A123-24
352001 75.00 2011-06-02 A123-56
451003 80.00 2010-10-19 A123-97
|
The output I'm getting from the below query
| Code: |
SELECT A.B_OFF#
,A.ID_USER
,B.CHK_#
,B.CHK_AMT
FROM TABLEA.A, TABLEB.B
WHERE A.P_ID = B.P_ID
AND ID_USER IN (761001,
761002,
760996,
760997,
760998)
;
---------+---------+---------+---------+-------
B_OFF# ID_USER CHK_# CHK_AMT
---------+---------+---------+---------+-------
300000620 761002 A123-24 50.00
310544110 760996 A123-56 75.00
310544220 760997 A123-97 80.00
|
Can you please tell me to get all rows from 2 tables even if there is no match found in TABLEB?
The output i'm looking is
| Code: |
---------+---------+---------+---------+-------
B_OFF# ID_USER CHK_# CHK_AMT
---------+---------+---------+---------+-------
300000610 761001
300000620 761002 A123-24 50.00
310544110 760996 A123-56 75.00
310544220 760997 A123-97 80.00
310544330 760998
|
|
|
| Back to top |
|
 |
chandan.inst
Active User

Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi Krishna,
I belive you want to write all rows from Table A and when you find a match in Table B write amounts from table B in report else populate spaces for.
Here you need to use left outer join as below
| Code: |
SELECT A.B_OFF#
,A.ID_USER
,B.CHK_#
, B.CHK_AMT
FROM TABLEA.A
LEFT OUTER JOINT
TABLEB.B
ON A.P_ID = B.P_ID
AND ID_USER IN (761001,
761002,
760996,
760997,
760998)
; |
When B.CHK_# and B.CHK_AMT are null you need to populate Spaces to your corresponding report variables
Regards,
Chandan |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|