Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combining two tables
Message
From
27/07/2012 10:11:37
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 7
Network:
Windows 2008 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01549418
Message ID:
01549420
Views:
49
>>I need some select/SQL advice please
>>
>>I am combinging two tables T1 & T2 they have customer numbers/Custno and quarter sales totals/qs
>>
>>T1 contains data for the year 2010 T2 contains data from the year 2011
>>
>>Data example is something like this;
>>
>>T1.Custno     T1.QS
>>001                   $150.00
>>004                   $650.00
>>008                   $50.00
>>012                    $70.00
>>060                    $95.00
>>
>> 
>>T1.Custno     T1.QS
>>001                   $350.00
>>002                   $550.00
>>008                   $750.00
>>035                    $10.00
>>060                    $595.00
>>
>>
>>I want to create a comparison table that includes all the records of both tables, but I want to match up the customers when they are the same.
>>I know I can do it with a scan/endscan type sort with conditions, but I was wondering if there was an easier way to do it with a select statement.
>>
>>the resulting table would look like this
>>
>>Custno               2011_QS            2010_QS
>>001                   $350.00                    $150.00
>>002                   $550.00                     $0.00
>>004                   $0.00                        $650.00                     
>>008                   $750.00                    $50.00
>>012                    $0.00                        $70.00
>>035                    $10.00                       $0.00
>>060                    $595.00                    $95.00
>>
>>
>>Thanks....
>
>You just need to join two tables, e.g.
>
>select T1.CustNo, T2.QS as 2011_QS, T1.QS as 2010_QS
>FROM Table1 T1 inner join Table2 T2 on T1.CustNo = T2.CustNo
I think you need an outer join
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform