sql - how to select the value from sub query result -
i have following 4 tables mentioned below , trying extract value acc_number sub query, please me optimized correct syntax
account table ------------------------- |acc_number | acc_name| ------------------------- account_details table --------------------------------- |acc_number |deal_number|deal_type| --------------------------------- deals table ------------------------------------ |deal_number |deal_type|dep_number | ------------------------------------ department table ------------------------ |dep_number | dep_name | ------------------------ select d.deal_number, d.d_type, dp.department_number deals d , department dp d.dep_number = dp.dep_number , d.deal_number not in (select acd.deal_number account_details acd, account ac ac.acc_number = acd.acc_number , deal_type = 'xxxx' , acd.deal_number = d.deal_number)
hi, if using
d.deal_number not in
means records join not present in account , account_details table, never acc_number particular deals?if ready alteration in current syntax, can play joins acc_number in query result:
example:
select d.deal_number, d.d_type, acd.acc_number, dp.department_number deals d join department dp on d.dep_number = dp.dep_number left join account_details acd on acd.deal_number = d.deal_number join account ac ac.acc_number = acd.acc_number deal_type = 'xxxx' , acd.deal_number = d.deal_number
Comments
Post a Comment