x

I'm returning two rows for each month_id. Only need the first one. Why am I getting 2?

SELECT Month_ID, B.BUSINESS_NAME, NTPV_TY_MTHLY AS nTPV, NET_CNT AS NET_CNT, MOBILE_NTPV_TY AS MOBILE_nTPV, Mobile_Net_Cnt AS MOBILE_CNT, XB_Net_Cnt, NET_CNT_LY, MOBILE_NTPV_LY, MOBILE_NET_CNT_LY, ACTV_BYR_CNT_TY, ACTV_BYR_CNT_LY, NEW_BYR_CNT_TY, NEW_BYR_CNT_LY, nTPV_credit_local, nTxn_credit, credit_actv_byr_cnt_ty, new_byr_cnt_Credit

FROM TABLEA AS A

JOIN TABLEM AS M ON A.SUB_ID = M.SUB_ID JOIN TABLEB AS B ON M.SUB_ID = B.SUB_ID

WHERE M.CUST_ID IN ('1435025301781261012', '1342416191137977536') AND A.MONTH_ID IN ('1419','1418','1417','1416','1415','1414','1413','1412','1411','1410','1409','1408','1407') GROUP BY Month_ID, B.BUSINESS_NAME, NTPV_TY_MTHLY, NET_CNT, MOBILE_NTPV_TY, Mobile_Net_Cnt, XB_Net_Cnt, NET_CNT_LY, MOBILE_NTPV_LY, MOBILE_NET_CNT_LY, ACTV_BYR_CNT_TY, ACTV_BYR_CNT_LY, NEW_BYR_CNT_TY, NEW_BYR_CNT_LY, nTPV_credit_local, nTxn_credit, credit_actv_byr_cnt_ty, new_byr_cnt_Credit

ORDER BY MONTH_ID, nTPV

more ▼

asked Apr 16 at 08:28 PM in Default

avatar image

hutchrob
1

(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

I can't really say because I can't see your data to say if two rows are meant to be returned.

However, I suspect that the joins might have something to do with it. If it was me I'd do some basic fault finding with my code, by reviewing the data without the joins, then introduce the first join, check the data and then introduce the final join.

Hope that helps, if not provide some sample data please.

more ▼

answered Apr 17 at 08:50 AM

avatar image

WRBI
61 1 3

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.

Topics:

x2221
x25
x1

asked: Apr 16 at 08:28 PM

Seen: 12 times

Last Updated: Apr 17 at 08:50 AM

Copyright 2018 Redgate Software. Privacy Policy