2

INSERT INTO Table2 ( Customer, Order_Date, Stamp_Date, Travelled_Distance, Units, Country, Comments )

SELECT

'CustomerFamily' As Customer, 
T1.Order_Date AS Order_Date, 
T1.Stamp_Date AS Stamp_Date, 
T1.Travelled_Distance-T2.Travelled_Distance AS Travelled_Distance, 
T1.Units AS Units, 
'Canada' AS Country, 
'' AS Comments

FROM

Table1 AS T1, 
Table1 AS T2

WHERE

T1.Customer='Jake' And 
T2.Customer='Mike' And 
T2.Order_Date=T1.Order_Date

ORDER BY

T1.Order_Date;

This is my append query that has a calculation in it ( for the days that jake and mike travel on same day it subtracts mikes travel distance from jakes)

the PROBLEM is that it does all the calculation fine and puts it into Table 2 but there is two rows which are the same for every single calculation.

why is it repeating twice? I can't spot the error

6
  • 1
    Is there any date in Table1 where Mike or Jake has travelled more than once in the same date? Commented Jul 21, 2011 at 22:46
  • yep lol thanks ypercube. the problem has been fixed Commented Jul 22, 2011 at 22:58
  • 1
    Is there some specific reason why you're using implicit joins instead of explicit? Commented Jul 22, 2011 at 23:41
  • jsut because when i tried them a few times before it kept giving me a JOIN format nto supported..or function nto supported or somethign not supported i dont quite remember Commented Jul 22, 2011 at 23:47
  • 1
    If there is any date in Table1 where someone has travelled more than once in the same date, then you should not use DISTINCT but GROUP BY and SUM(Travelled_Distance) Commented Jul 23, 2011 at 7:05

1 Answer 1

2

Try

SELECT DISTINCT 'CustomerFamily' As Customer, 
T1.Order_Date AS Order_Date, 
T1.Stamp_Date AS Stamp_Date, 
T1.Travelled_Distance-T2.Travelled_Distance AS Travelled_Distance, 
T1.Units AS Units, 
'Canada' AS Country, 
'' AS Comments
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.