General discussion

Locked

table join

By francoisv ·
Hey guys

what is the best way to join a table like this let say I've got a table Towns with a pkID and TownName field. And I've got a table named Destination with a pkID, DepartureID, DestinationID. Now destination and departure obviosly refer to the towns pkID field.

So how do I join these that If there is only 100 records in the Destination that only a 100 show with the names of the towns and not the nombers

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

wrong forum

by john.a.wills In reply to table join

post your question under Technical Q & A.

Collapse -

Here's an idea

by bmedlock In reply to table join

Try creating three views, or queries. I've named mine "View1", "View2" and "View3"
Here's the SQL:

CREATE VIEW dbo.view1
AS
SELECT dbo.Towns.TownName AS [Departure Town], dbo.Destination.PKID
FROM dbo.Destination INNER JOIN
dbo.Towns ON dbo.Destination.DepartureID = dbo.Towns.PKID

CREATE VIEW dbo.VIEW2
AS
SELECT dbo.Towns.TownName AS [Destination Town], dbo.Destination.PKID
FROM dbo.Destination INNER JOIN
dbo.Towns ON dbo.Destination.DestinationID = dbo.Towns.PKID

CREATE VIEW dbo.VIEW3
AS
SELECT dbo.view1.[Departure Town], dbo.VIEW2.[Destination Town], dbo.view1.PKID
FROM dbo.view1 INNER JOIN
dbo.VIEW2 ON dbo.view1.PKID = dbo.VIEW2.PKID


There are other ways, but this one requires less thinking. Hope it helps!

Back to Software Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums