开发者

SQL: How compare cells from different tables?

I have two tables - band and band2. Band开发者_如何学JAVA:

SQL: How compare cells from different tables?

and band2:

SQL: How compare cells from different tables?

The columns are equals. I'm using Access 2010. I want to SELECT rows WHERE band.Kampas<>band2.Kampas, but there isn't primary key so I can't use JOIN operation. Maybe someone has an idea?

The answer:

SQL: How compare cells from different tables?

Only in these rows band.Kampas<>band2.Kampas. Thanks in advance.


SELECT b2.*
FROM band2 b2
WHERE b2.kampas NOT IN (SELECT b1.kampas
                        FROM band b1 
                        WHERE b1.kampas IS NOT NULL)
  AND b2.kampas IS NOT NULL    


If I understand you correctly this is what you want:

Select * from band where kampas not in (select kampas from band2)
union
Select * from band2 where kampas not in (select kampas from band)

EDIT. Ok, might be that not in doesn't work in Access. It looks like this could work, though:

Select * from band2 where not exists (select * from band where band.kampas = band2.kampas)

This find a selection in the inner select where kampas's match and we want to pick those band2 lines that returns an empty selection in the inner select.

If you want to do this two-way (i.e. also find from band) just use union like I did in the first attempt.


How about this:

select * 
from Band as B1 
inner join Band2 as B2 
on B1.Stotis = B2.Stotis
where B1.Kampas <> B2.Kampas
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜