maliks
maliks

Reputation: 1112

Selecting data for different columns from other same SQL Server table column

I have a view named as This_View in the form:

Author  CoAuthor
----------------
677     901706
677     838459
677     901706
677     1695352
677     901706
1359    1695352
...  
...  

I have to select Name from another table against column i.e. Author and CoAuthor where value of Name for both Author and CoAuthor exist in the same column of Other_Table.

I have tried this:

SELECT name as Author, name as CoAuthor
FROM Other_Table AA
JOIN This_View YA ON YA.Author = AA.aid AND YA.CoAuthor = AA.aid
ORDER BY Author  

but not succeeded.

Upvotes: 0

Views: 53

Answers (1)

wiretext
wiretext

Reputation: 3342

you have to make different JOIN for Author and Coauthor

SELECT AA.name as Author, BB.name as CoAuthor
FROM This_View YA 
JOIN Other_Table AA ON YA.Author = AA.aid
JOIN Other_Table BB ON YA.CoAuthor = BB.aid
ORDER BY AA.name 

Upvotes: 1

Related Questions