Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
MGarriga
Starting Member
5 Posts |
Posted - 2009-08-07 : 14:12:35
|
| Hello,If I run the following query:select major,minor,COUNT(*)numaccyfrom EXTR_Accessorygroup by Major,Minororder by numaccy,Major,MinorI get 178710 rows.If instead I run the following query:SELECT a.Major, a.MinorFROM EXTR_Accessory a INNER JOIN EXTR_RPSale b ON a.Major = b.Major AND a.Minor = b.MinorGROUP BY a.Major, a.MinorORDER BY a.Major,a.MinorI get 154546 rows.What I am trying to do, is the same query above, but including a column with the Count of (Major+Minor), how they appear in the first query, so I tried the following query, with a result of 0 rows, when I know I should get 154546 rows:SELECT b.Major,b.Minor,a.NumAccyFROM (SELECT Major,minor, COUNT (*) as NumAccy FROM EXTR_Accessory GROUP BY Major,Minor) a INNER JOIN EXTR_RPSale b ON a.Major = b.Major AND b.Major = b.MinorORDER BY a.NumAccyWhat I am doing wrong?Thank you,Montse |
|
|
johnconstraint
Starting Member
23 Posts |
Posted - 2009-08-07 : 14:56:41
|
| Should your AND condition in your third query be like below ?AND a.minor = b.Minor |
 |
|
|
MGarriga
Starting Member
5 Posts |
Posted - 2009-08-07 : 19:32:42
|
| Thank you.I needed a break ;o) |
 |
|
|
|
|
|
|
|