Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

SQL question

Thread Tools
 
Search this Thread
 
Old Mar 13, 2003 | 04:36 PM
  #1  
Fosters's Avatar
Fosters
Thread Starter
Scooby Regular
 
Joined: Jul 2000
Posts: 2,145
Likes: 0
From: Islington
Post

Microsoft Access 97

Table A has all the information
Table B has some of the rows from table A
they both have the same columns

how do I get table A's rows minus table B's rows into table C?

mars bar for the most efficient solution (no cartesian selects please )

I've tried...
select x.1, x.2, x.3
from (select a.1, a.2, a.3 from tablea a
union
select b.1, b.2, b.3 from tableb b) x
group by x.1, x.2, x.3
having count(*)=1

...but it's not having it.


Reply
Old Mar 13, 2003 | 04:44 PM
  #2  
ChrisB's Avatar
ChrisB
Moderator
 
Joined: Dec 1998
Posts: 23,573
Likes: 0
From: Staffs
Post

Okay...

Table A has

Row with Keys : 1,2,3,4,5,6,7,8,9,10

Table B has

Rows with Keys : 1,2,3,4,5

So Table C will have 6,7,8,9,10?

This works for me:

SELECT DISTINCTROW tblOne.IndexID, tblOne.KeyID, tblOne.FieldB, tblOne.FieldC INTO tblThree
FROM tblOne LEFT JOIN tblTwo ON tblOne.KeyID = tblTwo.KeyID
WHERE (((tblTwo.KeyID) Is Null));

I think
Reply
Old Mar 13, 2003 | 04:47 PM
  #3  
camk's Avatar
camk
Scooby Regular
 
Joined: Mar 2000
Posts: 1,764
Likes: 0
Post

select * from tablea
where key_a not in(select key_b from tableb)
Reply
Old Mar 13, 2003 | 04:49 PM
  #4  
ChrisB's Avatar
ChrisB
Moderator
 
Joined: Dec 1998
Posts: 23,573
Likes: 0
From: Staffs
Post

That's a slightly quicker way of doing it
Reply
Old Mar 13, 2003 | 08:10 PM
  #5  
chiark's Avatar
chiark
Scooby Regular
 
Joined: Jun 2000
Posts: 13,735
Likes: 0
Post

The magic "not in" solution is the one you want
Reply
Old Mar 14, 2003 | 08:21 AM
  #6  
Fosters's Avatar
Fosters
Thread Starter
Scooby Regular
 
Joined: Jul 2000
Posts: 2,145
Likes: 0
From: Islington
Post

Were it only that simple chaps

table A column data | table B column data
a,b,c,d,e | a,b,c,d,e
a,f,c,d,e | a,f,c,d,e
a,b,c,d,f | a,b,c,d,e
a,b,c,d,e | a,b,c,d,g
x,b,c,d,t |
j,b,c,d,e | a,b,c,d,e
a,b,c,d,e | a,y,c,d,e
x,b,c,d,e | a,b,c,d,e
x,b,c,d,h |

none of them are keyed fields, and you can see row 1 and 2 are the only matching rows columns 1 to 5

I want rows 1 and 2 in table C and the remaining unmatched rows in tables D and E (from A and B, respectively).


Reply
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
Nov 4, 2021 07:12 PM
slimwiltaz
General Technical
20
Oct 9, 2015 07:40 PM
IanG1983
Wheels, Tyres & Brakes
2
Oct 6, 2015 03:08 PM
Brzoza
Engine Management and ECU Remapping
1
Oct 2, 2015 05:26 PM
the shreksta
Other Marques
26
Oct 1, 2015 02:30 PM




All times are GMT +1. The time now is 10:27 AM.