Utilities Blog by JuCa Cruz
If it happened to me before, maybe what I've posted here will help you.
Wednesday, October 27, 2010
My first official LEFT JOIN
When I was at school I always was afraid of using LEFT OR RIGHT Joins, well, almost 6 years after I'm done with school, I had to do my first one:
SELECT ACCT_ORDER.CUST_ID, ACCT_ORDER.ACCT_NUM, MTN_ORDER.mtn, MTN_ORDER.mtn_order_type, MTN_ORDER.mtn_order_state, MTN_ORDER.mtn_order_state_date, MTN_ORDER.bdy_mtn, MTN_ORDER.cidb_order_id, MTN_STATE.mtn_eligibility_state, MTN_STATE.mtn_eligibility_state_date, ACCT_ORDER.pos_order_id, ACCT_ORDER.pos_pre_order_id, ACCT_ORDER.pos_loc_cd, ACCT_ORDER.order_state, ACCT_ORDER.order_state_date FROM CUST_ACCT_ORDER ACCT_ORDER LEFT JOIN CUST_ACCT_MTN_ORDER MTN_ORDER ON ACCT_ORDER.acct_num = MTN_ORDER.acct_num AND ACCT_ORDER.cust_id = MTN_ORDER.cust_id AND ACCT_ORDER.cidb_order_id = MTN_ORDER.cidb_order_id LEFT JOIN CUST_ACCT_MTN_STATE MTN_STATE ON MTN_ORDER.cust_id = MTN_STATE.cust_id AND MTN_ORDER.acct_num = MTN_STATE.acct_num AND MTN_ORDER.mtn = MTN_STATE.mtn WHERE( (ACCT_ORDER.pos_order_id = p_pos_order_id AND ACCT_ORDER.pos_loc_cd = p_pos_loc_cd) OR ACCT_ORDER.pos_pre_order_id = p_pos_pre_order_id ) ORDER BY MTN_ORDER.mtn;
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment