Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
hyefive
Starting Member
16 Posts |
Posted - 2004-04-12 : 13:52:28
|
| Hi, SQL newbie here,I have two tables (TABLE1, TABLE2) with identical column structures. Each has colA, colB, colC, etc...All I'm trying to do is query certain fields (colA, colB) from both tables simultaneously and work with the resuting values but I'm having a difficult time of it.Is this possible?TIA, |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-04-12 : 13:56:30
|
| Let's assume Col1 is the Primary Key of BothSELECT a.Col1, b.Col1, a.Col2, b.Col2, ectFROM TableA aINNER JOIN TableB bON a.Col1 = b.Col1Brett8-) |
 |
|
|
hyefive
Starting Member
16 Posts |
Posted - 2004-04-12 : 14:04:35
|
| In this situation, TABLE1 and TABLE2 are in no way related, so does the Primary Key have any relevance?They just happen to have the same column structure.I want to SELECT the same columns from each table, and have all matching records put into one recordset.Is this any clearer? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2004-04-12 : 14:07:30
|
| Post a few rows from each table so that we can better help you. What do you mean by matching records?Tara |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2004-04-12 : 14:08:20
|
| Do you mean duplicates?SELECT Col1, Col2, Col3, ectFROM (SELECT Col1, Col2, Col3, ectFROM TableAUNION ALLSELECT Col1, Col2, Col3, ectFROM TableA) AS XXXGROUP BY Col1, Col2, Col3, ectHAVING COUNT(*) > 1Brett8-) |
 |
|
|
hyefive
Starting Member
16 Posts |
Posted - 2004-04-12 : 14:11:39
|
| Thanks again for the replies!I think the UNION operator is what I need here, so I'll start down that path...Have a nice day,hyefive |
 |
|
|
|
|
|
|
|