I have two tables which I join so that I may compare a field and extract records from one table where the field being compared is not in both tables:
Table A
---------
Comp Val
111 327
112 234
113 265
114 865
Table B
-----------
Comp2 Val2
111 7676
112 5678
So what im doing is to join both tables on Comp-Comp2, then I wish to select all values from Table A for which a corrssponding Comp does not exist in Table B. In this case, the query should result in:
Result
---------
Comp Val
113 265
114 865
Here is the query:
select * into Result from TableA
inner join TableB
on (TableB.Comp2 = TableA.Comp)
where TableB.Comp2 <> TableA.Comp
Problem is, it pulls values from both tables. Is there a way to select values from TableA alone without specifying the fields explicitly?
6条答案
按热度按时间jtjikinw1#
Just prefix the
*
with the desired table name, like this:0s0u357o2#
I think you want this, though:
That will find all records in A that don't exist in B.
nvbavucw3#
uxh89sit4#
You could also do a left join and then just return rows that do not match:
You can restrict the columns return like this, but it is typically better to not user the *, but to name all of the columns.
9avjhtql5#
For me works like this. TABLE ARE FOR TESTS
vpfxa7rd6#
SELECT A.* FROM RMS_User A LEFT JOIN RMS_Department D ON A.DepartmentId = D.Id WHERE D.Identifier = 'ADMIN'