Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Newbie Lost :) Please help

Author  Topic 

Stjepan
Starting Member

5 Posts

Posted - 2011-11-29 : 18:04:37
Hi all,


I have two tables:

[Articles]
- ID (number, PK)
- ArtName (text)
- Link (text)

[RelatedArticles]
- raID (number, PK)
- Related1 (number)
- Related2 (number)
- Related3 (number)

Related1...Related3 are IDs from Article Table.


I want now to create a query that will display RelatedArticles, and also to include new fields "ArtName" and "Link" which will take from table Articles by a given [Article]![ID]


I hope you understood me well!

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-30 : 01:38:42
its just a matter of three joins to master table

SELECT ra.Related1,
a1.ArtName,
a1.Link,
ra.Related2,
a2.ArtName,
a2.Link,
ra.Related3,
a3.ArtName,
a3.Link
FROM RelatedArticles ra
INNER JOIN Articles a1
ON a1.ID = ra.Related1
INNER JOIN Articles a2
ON a2.ID = ra.Related2
INNER JOIN Articles a3
ON a3.ID = ra.Related3


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Stjepan
Starting Member

5 Posts

Posted - 2011-11-30 : 18:36:00
Great, thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-01 : 00:16:16
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -