1

I have two tables, A1 and A2. I want to compare these two tables. I tried inner join but it doesn't give the required result.

These are the data in these tables,

Table A1

No. Address 
1  abc
1  abc
1  def
1  def

Table A2

No. Address
1    def
1    abc
1    abc
1    def

These two tables can only be joined by using No. column. So if I use INNER JOIN it gives 16 rows. I don't want that, I want only 4 rows to be displayed. This should be the output:

No.   Address   eq
1     abc      #
1     abc      *
1     abc      #
1     abc      #

Last column is displayed if address in A1 is equal to A2

4

2 に答える 2

2

A1 テーブルには存在するが A2 テーブルには存在しないレコードを検索します。

SELECT * FROM A1 WHERE NOT EXISTS (SELECT * FROM A2 WHERE A2.Id = A1.Id)
于 2013-01-01T00:25:36.310 に答える
0

ケースを使ってみる

select case when tablea1.address=tablea2.address then '*' else '#' end as eq from tablea1 内部で tablea2 を tablea1.=tablea2 に結合します。

それがあなたを助けることを願っています。

于 2013-03-31T19:43:31.283 に答える