Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Number of Records without distinct - duplicate ?

Status
Not open for further replies.

Cap2010

Programmer
Mar 29, 2000
196
CA
hi
What's the error, below SQL finds number of records

SELECT distinct
m1.Mtrl_id,
Month(m2.date) AS Mth,
Count(Year(m2.Date)) AS TotalCount
FROM MasterMtrl m1
INNER JOIN MtrlTransaction m2 ON
m1.Mtrl_id = m2.Mtrl_id
WHERE
(m2.Status<>"1") AND
(Year(m2.date)=2004))
GROUP BY m1.Mtrl_id, Month(m2.date)
ORDER BY m1.Mtrl_id;



On giving the word distinct in SQL it gives exactly what I am looking for
and without distinct it repeats the same number 30 times each month and 29 times for Feb.

Want to do without using Distinct in SQL, as the data is not repeating also. As the records per item is only one for each day

Without using distinct records are displayed
number of times i.e.

Without Distinct
ItemNo Mth Count
A0001 1 30
A0001 1 30
A0001 1 30
A0001 1 30
A0001 2 35
A0001 2 35

A0002 1 20
A0002 1 20
A0002 2 15
A0002 2 15

With Distinct
ItemNo Mth Count
A0001 1 30
A0001 2 35

A0002 1 20
A0002 2 15

How to do without distinct
 
'On giving the word distinct in SQL it gives exactly what I am looking for'

This is usually enough for most people:)-)

Why are you looking for a different solution?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top