marmar
marmar

Reputation: 113

Querying item that is NOT EQUAL in the second table

I have a newbie question about oracle Query. I want to query all the items that are not equal in 2 tables.

my tables are like this

A,

NAME  VAL1 VAL2
HEAD1 400  80
HEAD2 300  70
HEAD3 299  49
HEAD4 199  59

and table B,

NAME  VAL1 VAL2
HEAD1 400  80
HEAD2 300  70
HEAD3 200  60
HEAD4 100  50

and my query,

SELECT A.NAME, A.VAL1 VALUEA1, B.VAL1 VALUEB1 FROM A, B
WHERE (SELECT B.VAL1 FROM B WHERE A.VAL1 != B.VAL1)

and my expected output would be like this

NAME  VALUEA1 VALUEB1
HEAD3 299     200
HEAD4 199     100

Please help me with my query

Upvotes: 0

Views: 54

Answers (2)

sgeddes
sgeddes

Reputation: 62851

I think a standard JOIN should work:

select a.name, a.val1, b.val1 as bval1
from a 
  join b on a.name = b.name
where a.val1 <> b.val1

Upvotes: 3

Dhwani
Dhwani

Reputation: 7626

Try this:

Select A.Name, A.VAL1 AS VALUEA1, A.VAL2 AS VALUEB1 
From TableA as A, TableB As B
Where A.NAME = B.NAME AND A.VAL2 != B.VAL2

Upvotes: 2

Related Questions