Jump to content

Sql Query Doubt


Recommended Posts

Posted
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
Posted

Do it join with same table with joining condition a.parent supplier id = b.parent supplier id

Posted

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

Posted

parent supplier name ni ela decide chestunnav???

 

evry third value for parent supplier id aa?? or evry last value for parent supplier id aa??

Posted

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
Posted

Sarigga soodu ba,

Parent supplier ids match ayina record padutunnadu

 

hmm crrt e.. obsvre cheyyale... :3D_Smiles_38:

 

 

 

Posted

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

Posted

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;

Posted

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
Posted

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... 

Posted

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 :)

Posted

Ok...ee madhya direct sql script rase situation lekunda unde :)

 

just telling man... just in case laaga... P8aeIeu.gif

Posted

just telling man... just in case laaga... P8aeIeu.gif

Nice uncle...munde accepted P8aeIeu.gif

×
×
  • Create New...