nikhilboorla Posted March 16, 2015 Report Posted March 16, 2015 suppliers table Parent supplier id supp id supplier name 123 ------------> 321 -----> aaa 123 ------------> 231 -----> bbb 123 abc 456 ------------> 654 -----> ddd 546 eee 456 def 789 -----------> 987 -----> ggg 879 hhh 789 ghi expected output: ---------------------- parent supplier id parent supplier name suppid supp name 123 abc 321 aaa 123 abc 231 bbb 456 def 654 ddd 456 def 546 eee 789 ghi 987 ggg 789 ghi 879 hhh
sunnygm Posted March 16, 2015 Report Posted March 16, 2015 Do it join with same table with joining condition a.parent supplier id = b.parent supplier id
TelugoduNenu Posted March 16, 2015 Report Posted March 16, 2015 idi try cheyyi Syntax errors kani nee db ki taggattu syntax gani marchuko select t1. ParentSupplierId,t1. ParentSupplierName,t2.SuppID,t2.SupplierName from SupplierTable t2 Join (select ParentSupplierId,SupplierName as ParentSupplierName from Supplier table where ParentSupplierId = SuppId) t1 on t2. ParentSupplierId = t1. ParentSupplierId
mtkr Posted March 16, 2015 Report Posted March 16, 2015 parent supplier name ni ela decide chestunnav??? evry third value for parent supplier id aa?? or evry last value for parent supplier id aa??
TelugoduNenu Posted March 16, 2015 Report Posted March 16, 2015 parent supplier name ni ela decide chestunnav??? evry third value for parent supplier id aa?? or evry last value for parent supplier id aa?? Sarigga soodu ba, Parent supplier ids match ayina record padutunnadu
mtkr Posted March 16, 2015 Report Posted March 16, 2015 Sarigga soodu ba, Parent supplier ids match ayina record padutunnadu hmm crrt e.. obsvre cheyyale... :3D_Smiles_38:
mtkr Posted March 16, 2015 Report Posted March 16, 2015 idi try cheyyi Syntax errors kani nee db ki taggattu syntax gani marchuko select t1. ParentSupplierId,t1. ParentSupplierName,t2.SuppID,t2.SupplierName from SupplierTable t2 Join (select ParentSupplierId,SupplierName as ParentSupplierName from Supplier table where ParentSupplierId = SuppId) t1 on t2. ParentSupplierId = t1. ParentSupplierId deeniki inko line add cheyyali.. ippude tried... abve query resulting all recds so matched ni eliminate cheyyaalii.. select t1. parentSupplierid,t1. ParentSupplierName,t2.SuppID,t2.SupplierName from suppliers t2 Join (select ParentSupplierId,SuppId,SupplierName as ParentSupplierName from suppliers where parentSupplierid = SuppId) t1 on t2. ParentSupplierId = t1. ParentSupplierId and t2. SuppId <> t1. ParentSupplierId
pythonic Posted March 16, 2015 Report Posted March 16, 2015 select a.suppid as parent supplier id, a.supplier_name as parent_supplier_name, b.suppid, b.supp_name from suppliers a, suppliers b where a.suppid = b.parent_supp_id;
loveindia Posted March 16, 2015 Report Posted March 16, 2015 enjoy man... DECLARE @Supplier TABLE ( ParentSupplierID INT, SupplierID INT, SupplierName VARCHAR(10) ) INSERT INTO @Supplier VALUES (123, 111, 'ABC'), (123, 222, 'BCE'), (NULL, 123, 'AAA') SELECT Child.ParentSupplierID, Parnt.SupplierName, Child.SupplierID, Child.SupplierName FROM @Supplier child INNER JOIN @Supplier parnt ON child.ParentSupplierID = parnt.SupplierID
loveindia Posted March 16, 2015 Report Posted March 16, 2015 select a.suppid as parent supplier id, a.supplier_name as parent_supplier_name, b.suppid, b.supp_name from suppliers a, suppliers b where a.suppid = b.parent_supp_id; ANSI Sql format of writing... many code reviewers will tend to fail this way of writing these days man... but it still happens to produce result sets...
pythonic Posted March 16, 2015 Report Posted March 16, 2015 ANSI Sql format of writing... many code reviewers will tend to fail this way of writing these days man... but it still happens to produce result sets... Ok...ee madhya direct sql script rase situation lekunda unde :)
loveindia Posted March 16, 2015 Report Posted March 16, 2015 Ok...ee madhya direct sql script rase situation lekunda unde :) just telling man... just in case laaga...
pythonic Posted March 16, 2015 Report Posted March 16, 2015 just telling man... just in case laaga... Nice uncle...munde accepted
Recommended Posts