Join Within table's Column

Analyst_SQL 3,531 Reputation points
2022-04-17T08:47:11.34+00:00

i want to join column within table ,below is data

Create table #Concategory (Cat_ID int,Cat_name varchar(50),Port_ID int,Acc_type varchar(50))  
  
insert into   #Concategory values (1,'Akhter','','Port')  
  
insert into   #Concategory values (2,'Karchi','','Port')  
  
  
insert into   #Concategory values (3,'Pakistan',1,'Location')  
  
insert into   #Concategory values (4,'Iran',2,'Location')  
  
![193636-image.png][1]  
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,644 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,547 questions
{count} votes

Accepted answer
  1. Erland Sommarskog 100.8K Reputation points MVP
    2022-04-17T17:22:25.137+00:00

    Now i have change Port_ID=1 from 1 to 2

    Then it makes more sense.

    SELECT b.Cat_ID, b.Cat_name, a.Cat_name AS Port_Name
     FROM   #Concategory a
     JOIN   #Concategory b ON b.Port_ID = a.Cat_ID
    
    0 comments No comments

0 additional answers

Sort by: Most helpful