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 13 March 2003, 04:36 PM
  #1  
Fosters
Scooby Regular
Thread Starter
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
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.


Old 13 March 2003, 04:44 PM
  #2  
ChrisB
Moderator
 
ChrisB's Avatar
 
Join Date: Dec 1998
Location: Staffs
Posts: 23,573
Likes: 0
Received 0 Likes on 0 Posts
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
Old 13 March 2003, 04:47 PM
  #3  
camk
Scooby Regular
 
camk's Avatar
 
Join Date: Mar 2000
Posts: 1,764
Likes: 0
Received 0 Likes on 0 Posts
Post

select * from tablea
where key_a not in(select key_b from tableb)
Old 13 March 2003, 04:49 PM
  #4  
ChrisB
Moderator
 
ChrisB's Avatar
 
Join Date: Dec 1998
Location: Staffs
Posts: 23,573
Likes: 0
Received 0 Likes on 0 Posts
Post

That's a slightly quicker way of doing it
Old 13 March 2003, 08:10 PM
  #5  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

The magic "not in" solution is the one you want
Old 14 March 2003, 08:21 AM
  #6  
Fosters
Scooby Regular
Thread Starter
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
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).


Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
slimwiltaz
General Technical
20
09 October 2015 07:40 PM
IanG1983
Wheels, Tyres & Brakes
2
06 October 2015 03:08 PM
Brzoza
Engine Management and ECU Remapping
1
02 October 2015 05:26 PM
the shreksta
Other Marques
26
01 October 2015 02:30 PM



Quick Reply: SQL question



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