How to use group by clause to join two tables....

Posted by Sheeba under ASP.NET on 4/30/2011 | Points: 10 | Views : 2439 | Status : [Member] | Replies : 1
hi


How to use group by clause to join two tables....


My query is like this

SELECT DISTINCT A.FEATNO AS SNO,A.MEASUREMENT AS MEASUREFEATURE,A.NOMINAL_DIMENSION AS NOMINALVALUE,A.NOMINAL_PLUS AS NPLUS,A.NOMINAL_MINUS AS NMINUS,B.ACTUAL_DIMENSION AS ACTVALUE,B.DEVIATION AS DEVIATION,B.OUT_OF_TOLERENCE AS OUTOFTOLERANCE,B.REMARKS AS REMARKS,'"+Batch_No+"' AS BATCHNO,B.PARTNO AS PARTNO FROM FEATURES A JOIN DETAIL B ON A.FEATNO=B.SNO WHERE B.BATCH_CODE='" + Batch_Code + "' AND B.REMARKS='" + ReportName + "' ORDER BY A.FEATNO ASC


Thanks




Responses

Posted by: Prabhakar on: 4/30/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Sheeba


Try This . . it's working for u , ,

SELECT DISTINCT A.FEATNO AS SNO, A.MEASUREMENT AS MEASUREFEATURE, A.NOMINAL_DIMENSION AS NOMINALVALUE,
A.NOMINAL_PLUS AS NPLUS, A.NOMINAL_MINUS AS NMINUS, B.ACTUAL_DIMENSION AS ACTVALUE, B.DEVIATION AS DEVIATION,
B.OUT_OF_TOLERENCE AS OUTOFTOLERANCE, B.REMARKS AS REMARKS, '"+Batch_No+"' AS BATCHNO, B.PARTNO AS PARTNO
FROM dbo.FEATURES A INNER JOIN
dbo.DETAIL B ON A.FEATNO = B.SNO
WHERE (B.BATCH_CODE = '" + Batch_Code + "')
GROUP BY A.FEATNO, A.MEASUREMENT, A.NOMINAL_DIMENSION, A.NOMINAL_PLUS, A.NOMINAL_MINUS, B.ACTUAL_DIMENSION, B.DEVIATION,
B.OUT_OF_TOLERENCE, B.REMARKS, B.PARTNO
HAVING (B.REMARKS = '" + ReportName + "')
ORDER BY A.FEATNO


Best Regard's
Prabhakar

Sheeba, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response