Click here to Skip to main content
15,922,512 members
Home / Discussions / Database
   

Database

 
AnswerRe: ER Diagrams Pin
Colin Angus Mackay18-Jan-06 5:28
Colin Angus Mackay18-Jan-06 5:28 
QuestionMoving data between servers Pin
Russell Nash18-Jan-06 2:54
Russell Nash18-Jan-06 2:54 
GeneralRe: Moving data between servers Pin
PolarbearDK18-Jan-06 4:57
PolarbearDK18-Jan-06 4:57 
AnswerRe: Moving data between servers Pin
Farhan Noor Qureshi18-Jan-06 7:34
Farhan Noor Qureshi18-Jan-06 7:34 
Questionquery for unique customers Pin
imsathy18-Jan-06 2:22
imsathy18-Jan-06 2:22 
AnswerRe: query for unique customers Pin
Colin Angus Mackay18-Jan-06 2:50
Colin Angus Mackay18-Jan-06 2:50 
QuestionRe: query for unique customers Pin
imsathy18-Jan-06 3:17
imsathy18-Jan-06 3:17 
AnswerRe: query for unique customers Pin
Colin Angus Mackay18-Jan-06 4:00
Colin Angus Mackay18-Jan-06 4:00 
imsathy wrote:
this query works when totalValue is not added in the query


That is correct, it must be in the GROUP BY clause or part of an aggregate. If you want the totalValue from the corresponding date you need to create a subquery.
SELECT customerId, [date], totalValue
FROM business_orders AS bo
INNER JOIN (
    SELECT customerId, max(dateOfPurchase) AS [date]
    FROM business_orders 
    WHERE shopId = '9F5DF' 
    GROUP BY customerId) AS ld ON 
        bo.customerId = ld.customerID AND 
        bo.[dateOfPurchase] = ld.[date]


I also removed the DISTINCT keyword as the GROUP BY effectively does that already and so it was redundant.

CAVEAT: If you have two or more orders on the same dateOfPurchace then you will get duplicates for an individual customer. There is nothing you can do about that as there is not enough date to determine which was really the last purchase.

ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell

GeneralRe: query for unique customers Pin
imsathy18-Jan-06 18:32
imsathy18-Jan-06 18:32 
QuestionHow to assign dataset in Reporting Services 2005? Pin
Diego F.17-Jan-06 22:48
Diego F.17-Jan-06 22:48 
Questionmultiple update problem in datagrid Pin
sood_is_in17-Jan-06 21:24
sood_is_in17-Jan-06 21:24 
AnswerRe: multiple update problem in datagrid Pin
Alexandru Serban18-Jan-06 10:59
professionalAlexandru Serban18-Jan-06 10:59 
QuestionNeed Help With Creating an Easy Code. Pin
CoMMyz17-Jan-06 21:19
CoMMyz17-Jan-06 21:19 
AnswerRe: Need Help With Creating an Easy Code. Pin
Russell Nash18-Jan-06 2:58
Russell Nash18-Jan-06 2:58 
QuestionNT User List Pin
Bob Zagars17-Jan-06 20:08
Bob Zagars17-Jan-06 20:08 
AnswerRe: NT User List Pin
Colin Angus Mackay17-Jan-06 20:54
Colin Angus Mackay17-Jan-06 20:54 
GeneralRe: NT User List Pin
Bob Zagars17-Jan-06 23:52
Bob Zagars17-Jan-06 23:52 
GeneralRe: NT User List Pin
S Douglas18-Jan-06 0:40
professionalS Douglas18-Jan-06 0:40 
GeneralRe: NT User List Pin
Bob Zagars18-Jan-06 5:46
Bob Zagars18-Jan-06 5:46 
GeneralRe: NT User List Pin
S Douglas18-Jan-06 5:53
professionalS Douglas18-Jan-06 5:53 
Questionhow to access the Sql Server Publicly Pin
raheeli17-Jan-06 18:15
raheeli17-Jan-06 18:15 
AnswerRe: how to access the Sql Server Publicly Pin
Bob Zagars17-Jan-06 20:18
Bob Zagars17-Jan-06 20:18 
QuestionMap linked server to a constant Pin
12324r32353217-Jan-06 16:34
12324r32353217-Jan-06 16:34 
QuestionHow to use Insert/Update/Delete.... Pin
welbert17-Jan-06 15:48
welbert17-Jan-06 15:48 
GeneralSQL Server 2005 Developer Edition Network Connections... Pin
code-frog17-Jan-06 12:51
professionalcode-frog17-Jan-06 12:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.