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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Neded help with join two tables count return too many

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I have two tables, one stores a record for each item each time it is used. The second holds the main item list and has a record for each user. So an item could be in the table multiple times. I see now this needs to better normalized.
But is there a way to make the following query return one record instead of counting 2 which is currently how many of a particular item are in the main table ([grocery_Items-rename])

Here is my SQL statement
Code:
Select distinct(i.UPCode), Count(i.UPCode) as TotalUsed ,[Description], 
t.[UserName]
from [grocery_Items_Tracking] t inner join [grocery_Items-rename] i on i.UPCode = t.UPCode  
Group by i.UPCode,[Description] ,t.UserName
Having t.UserName = 'llh123' 
Order by TotalUsed DESC

TIA
Doug

DougP
 
FYI: this is the result of the above query

UPCode StoreID UserName DateAdded RecordID
1230000033 5 llh123 2019-01-10 05:09:04.057 2113

DougP
 
Impossible, returned fields "of the above query":

[pre]
UPCode TotalUsed Description UserName
[/pre]
:)


---- Andy

There is a great need for a sarcasm font.
 
I went a different route, case closed

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top