Where Not In / Minus?

jaybee3

Active Member
Joined
Jun 28, 2010
Messages
307
It's been a while since I've had to use SQL and that was Oracle. Basically I have two tables and I want to just display the items from table a that aren't in table b. Below are the methods of how I thought you would do it, but it doesn't bring in the right results. (The fields are all hypothetical, but fullField has the same format as b.details

Code:
SELECT 
   a2.fullField
FROM (
   SELECT
      a.f1, a.f2, a.f2, a.f1 & "-" & a.f2 & "-" & a.f3 As fullField
   FROM
      tableA a) AS a2
WHERE
   a2.fullField NOT IN (
   SELECT
      b.details
   FROM
      tableB b)
;


Code:
SELECT 
   a2.fullField
FROM (
   SELECT
      a.f1, a.f2, a.f2, a.f1 & "-" & a.f2 & "-" & a.f3 As fullField
   FROM
      tableA a) AS a2
MINUS
SELECT
   b.details
FROM
   tableB b
;

Any help would be much appreciated :)
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
This looks right but I'm not sure you meant to duplicate f2:
Code:
SELECT 
   a2.fullField
FROM (
   SELECT
      a.f1, a.f2, [COLOR="Red"][B]a.f2,[/B][/COLOR] a.f1 & "-" & a.f2 & "-" & a.f3 As fullField
   FROM
      tableA a) AS a2
WHERE
   a2.fullField NOT IN (
   SELECT
      b.details
   FROM
      tableB b)
;

MINUS is not a very commonly supported operation so it's probably not an option here. What kind of database are you querying and how are you running the query? Do you have any sample data to show what you want to accomplish?
 
Upvote 0
Note: for the record, the above construction does work tested in an access database (I used one table with records:

TableA (three fields, two rows)
a b c
d e f

TableB (one field, one row)
a-b-c

 
Upvote 0

Forum statistics

Threads
1,215,564
Messages
6,125,581
Members
449,237
Latest member
Chase S

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top