Click to See Complete Forum and Search --> : a sql query


handa_varun
May 27th, 2005, 09:18 AM
i have an query

There are four tables::
table_1 :: date,acct_ref,prod_ref,short_qty,long_qty
table_2:: acct_num,date,cus,Qty
table_3:: acct_ref,acct_num,acct_name
table_4:: prod_ref,cus

use table_3 to join between acct_num and acct_ref & table_4 to join cusip and prod_hub

table_1 has (-ve)qty in short_qty & (+ve)qty in long_qty whereas qty column in table2 has both (-ve) & (+ve) qty in one column only.
There can be either a (-ve)qty or (+)qty

Requirement:: To identify where the qty is different from table1 & table2 & for which all accounts

please suggest the sql query to do so

its urgent

Regards
Varun

JeffB
May 29th, 2005, 01:32 PM
I'm really not sure this is good, but try it and use it as a start, I'm basicly just trying to cover the relation between tables, see if this is correct:

SELECT table_1.date, table_3.acct_name, table_2.qty, table_1.short_qty, table_1.long_qty
FROM ((table_1 INNER JOIN table_3 ON table_1.acct_ref = table_3.acct_ref) INNER JOIN table_2 ON table_3.acct_num = table_2.acct_num) INNER JOIN table_4 ON (table_4.prod_ref = table_1.prod_ref) AND (table_2.cus = table_4.cus);

JeffB