Comparing columns from different tables (merged by LF) [message #263052] |
Tue, 28 August 2007 23:16 |
ilangoraj
Messages: 5 Registered: August 2007
|
Junior Member |
|
|
I need check a column value from two different Table
I had the Query Like this
-----------------------------------------------------
SELECT CASE WHEN
a.col_1 = c.col_1 AND
a.col_2 = c.col_2 AND
a.col_3 = c.col_3 AND
a.col_4 = c.col_4 AND
a.col_5 = c.col_5 AND
a.col_6 = c.col_6 THEN 'equal'
WHEN
a.col_1 > c.col_1 AND
a.col_2 > c.col_2 AND
a.col_3 > c.col_3 AND
a.col_4 > c.col_4 AND
a.col_5 > c.col_5 AND
a.col_6 > c.col_6 THEN 'high'
WHEN
a.col_1 < c.col_1 AND
a.col_2 < c.col_2 AND
a.col_3 < c.col_3 AND
a.col_4 < c.col_4 AND
a.col_5 < c.col_5 AND
a.col_6 < c.col_6 THEN 'low'
ELSE
'unequal'
END as status
FROM
Table1 a,
Table2 b
Table1 c,
Table2 d
WHERE a.Prim_Key = b.Prim_Key
AND b.retrieve_key = Value1
and c.Prim_Key = d.Prim_Key
AND d.retrieve_key = Value2
-----------------------------
retrieve_key key values Will be different
|
|
|
|
|
|
|
|
|
i don't follow rules: i need to compare column of two tables [message #263126 is a reply to message #263052] |
Wed, 29 August 2007 02:41 |
ilangoraj
Messages: 5 Registered: August 2007
|
Junior Member |
|
|
i need to check column value of one query1 to query2
query1 :
--------
SELECT col1,
col2,col3,col4,col5
FROM Table1 a,
Table2 b
WHERE Table2 .Fieldname = 'InputValue1';
query 2:
--------
SELECT col1,
col2,col3,col4,col5
FROM Table1 a,
Table2 b
WHERE Table2 .Fieldname = 'InputValue2';
since Input value(InputValue1 and InputValue2) are different so the resultant output changes. so when i try to join this query.it returns Cartesian value. Need to compare the col1 from first query1 with query2
Let Me Know as soon as possible
[Updated on: Thu, 30 August 2007 07:52] by Moderator Report message to a moderator
|
|
|
|
Re: urgent:i need to compare column of two tables [message #263207 is a reply to message #263126] |
Wed, 29 August 2007 07:02 |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
I'd use UNION ALL personaly. (Untested Code)SELECT 'query 1' source, col1
FROM Table1 a,
Table2 b
WHERE Table2 .Fieldname = 'InputValue1'
UNION ALL
SELECT 'query 2' source,col1,
FROM Table1 a,
Table2 b
WHERE Table2 .Fieldname = 'InputValue2'
order by 2,1
|
|
|