Joining multiple fields to one in another table

user3790375

I have two tables:

tblItinerary

ID | Place1 | Time1 | Place2 | Time2 | Place3 | Time3 |
1  | 1      |   10  |   2    |   23  |    1   |   21  |
2  | 2      |   5   |   3    |   4   |    1   |   12  |

tblPlaces

ID | PlaceName |
1  | Austria   |
2  | Germany   |
3  | India     |

I want do a WHERE tblItinerary = 1 to see the result set as:

Place1  | Place2  | Place3  |
Austria | Germany | Austria |

Right now the direction I have is something like

SELECT tblPlaces.PlaceName
 FROM tblPlaces
 JOIN tblPlaces.PlaceName
 ON tblItinerary.Place1 = tblPlaces.PlaceName
 JOIN tblPlaces.PlaceName
 ON tblItinerary.Place2 = tblPlaces.PlaceName
 JOIN tblPlaces.PlaceName
 ON tblItinerary.Place3 = tblPlaces.PlaceName
 WHERE tblItinerary.ID = 1;
potashin

The idea is correct, but there are some mistakes: to join one table multiple times, you should use unique aliases for each table. Also, you have not actually joined tblItinerary anywhere and your join syntax is incorrect (your attempt to join tblPlaces.PlaceName instead of tblPlaces). Try the following:

select p1.PlaceName as Place1
     , p2.PlaceName as Place2
     , p3.PlaceName as Place3
from tblItinerary i
join tblPlaces p1 on i.Place1 = p1.ID
join tblPlaces p2 on i.Place2 = p2.ID
join tblPlaces p3 on i.Place3 = p3.ID
where i.ID = 1;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Joining table into 4 columns and show another fields

From Dev

Rails: Joining by one table OR another table

From Dev

Joining DISTINCT values from one table to Another

From Dev

Joining multiple tables to one table in sql

From Dev

Joining row from one table with the sum value from another table

From Dev

Joining to another table or not?

From Dev

A simpler way of joining multiple columns to one look up table

From Dev

Joining two tables together with multiple results in one table

From Dev

PostgreSQL joining multiple table

From Dev

Joining of Multiple table

From Dev

Validate fields from one table to another in MySQL

From Dev

joining a table to another table in pandas

From Dev

SQL Multiple Joining with same fields

From Dev

SSRS Joining datasets on multiple fields

From Dev

Find records on multiple fields not in another table

From Dev

SQL Count multiple fields in another table

From Dev

SQL - Where In one table not the other (Multiple Fields)

From Dev

Replace one fields value with another fields value for every row of a table

From Dev

SQL joining a table containing multiple/duplicate values, to both fields on a table that is 1 to 1

From Dev

Specifying SELECT, then joining with another table

From Dev

PostgreSQL: Joining the count of another table

From Dev

How to Relate Two Fields in One Table to One Field in Another

From Dev

SQL - Fill one table from fields of another table

From Dev

SQL - Fill one table from fields of another table

From Dev

How to insert fields extracted from XML in one table into another table?

From Dev

Joining Different Tables with one table coumn name and another table's coumn values

From Dev

mySQL DELETE from one table using field from natural joining with another table?

From Dev

Selecting data from one table and joining another table for the main "key" is quite slow

From Dev

Joining Different Tables with one table coumn name and another table's coumn values

Related Related

  1. 1

    Joining table into 4 columns and show another fields

  2. 2

    Rails: Joining by one table OR another table

  3. 3

    Joining DISTINCT values from one table to Another

  4. 4

    Joining multiple tables to one table in sql

  5. 5

    Joining row from one table with the sum value from another table

  6. 6

    Joining to another table or not?

  7. 7

    A simpler way of joining multiple columns to one look up table

  8. 8

    Joining two tables together with multiple results in one table

  9. 9

    PostgreSQL joining multiple table

  10. 10

    Joining of Multiple table

  11. 11

    Validate fields from one table to another in MySQL

  12. 12

    joining a table to another table in pandas

  13. 13

    SQL Multiple Joining with same fields

  14. 14

    SSRS Joining datasets on multiple fields

  15. 15

    Find records on multiple fields not in another table

  16. 16

    SQL Count multiple fields in another table

  17. 17

    SQL - Where In one table not the other (Multiple Fields)

  18. 18

    Replace one fields value with another fields value for every row of a table

  19. 19

    SQL joining a table containing multiple/duplicate values, to both fields on a table that is 1 to 1

  20. 20

    Specifying SELECT, then joining with another table

  21. 21

    PostgreSQL: Joining the count of another table

  22. 22

    How to Relate Two Fields in One Table to One Field in Another

  23. 23

    SQL - Fill one table from fields of another table

  24. 24

    SQL - Fill one table from fields of another table

  25. 25

    How to insert fields extracted from XML in one table into another table?

  26. 26

    Joining Different Tables with one table coumn name and another table's coumn values

  27. 27

    mySQL DELETE from one table using field from natural joining with another table?

  28. 28

    Selecting data from one table and joining another table for the main "key" is quite slow

  29. 29

    Joining Different Tables with one table coumn name and another table's coumn values

HotTag

Archive