Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Sql Table Join?

I have two table from which i am importing Data using SQl
Query. Both table got several identical filelds while
some fields do not appear in both (some fields are in
table A but not in table B and vice versa)

Is it possible that I can get data from both tables to a
single sheet either with identical fields only or even
including un identical fields?

Identical fields only will also help me.

any code example will be much helpful

Thanks

Soniya

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Sql Table Join?

"Soniya" wrote ...

I have two table from which i am importing Data using SQl
Query. Both table got several identical filelds while
some fields do not appear in both (some fields are in
table A but not in table B and vice versa)

Is it possible that I can get data from both tables to a
single sheet either with identical fields only or even
including un identical fields?

Identical fields only will also help me.


Rows common to both tables:

SELECT T1.MyKeyCol, T1.MyDataCol
FROM Table1 T1
INNER JOIN Table2 T2
ON T1.MyKeyCol = T2.MyKeyCol;

Rows in table1 that are not in table2:

SELECT T1.MyKeyCol, T1.MyDataCol
FROM Table1 T1
LEFT JOIN Table2 T2
ON T1.MyKeyCol = T2.MyKeyCol
WHERE T2.MyKeyCol IS NULL;

Rows in table2 that are not in table1:

SELECT T2.MyKeyCol, T2.MyDataCol
FROM Table1 T1
RIGHT JOIN Table2 T2
ON T1.MyKeyCol = T2.MyKeyCol
WHERE T1.MyKeyCol IS NULL;

Rows from both tables, no duplicates:

SELECT T1.MyKeyCol, T1.MyDataCol
FROM Table1 T1
UNION
SELECT T2.MyKeyCol, T2.MyDataCol
FROM Table2 T2;

Rows from both tables, including duplicates:

SELECT T1.MyKeyCol, T1.MyDataCol
FROM Table1 T1
UNION ALL
SELECT T2.MyKeyCol, T2.MyDataCol
FROM Table2 T2
ORDER BY 1;

Jamie.

--
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can i join these two formulas? Frustrated Excel Worksheet Functions 4 December 31st 09 04:12 AM
Join tables like inner join in Access ryanp Excel Discussion (Misc queries) 2 July 18th 08 03:35 PM
How do I join two workbooks into one pivot table? Eqa Excel Worksheet Functions 0 March 29th 07 07:54 AM
Can you join multiple databases using a pivot table? lbraunbe Excel Discussion (Misc queries) 1 June 30th 06 01:21 AM
Msquery and join titi Excel Discussion (Misc queries) 2 April 17th 06 02:19 PM


All times are GMT +1. The time now is 12:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"