Getting a value from another table for multiple columns

Salih Erikci

I have a table City with two fields, CityCode and RegionCode I have another table Code with two fields Code and CodeMeaning

I want to write a select statement that will display both cityCode, regionCode and their meanings for each city.

If i had to get one meaning from Code table i could do it with join but i don't know how to get values for both columns.

City Table Data
------------------------
CityCode     RegionCode
34             53
41             43

Code Table Data
-----------------
Code        Meaning
34          New York
41          Boston
53          North
43          South


Desired Output
------------------
CityCode     RegionCode    Region   City
34             53          North    New York
41             43          South    Boston
Gordon Linoff

Use two joins:

select cc.meaning as city, cr.meaning as region
from city c left join
     code cc
     on c.citycode = cc.code left join
     code cr
     on c.regioncode = cr.code

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

LinqtoSQL Getting a value from another table

From Dev

Copy multiple columns from a table to another table with extra columns

From Dev

Fill multiple columns with value from another dataframe

From Dev

Update multiple columns of a table using aggregate values from another table

From Dev

Updating a table from another table with multiple columns in sqlalchemy

From Dev

Update multiple columns of a table using aggregate values from another table

From Dev

Display records from one table which is not in another table by multiple columns

From Dev

Update Table by getting maximum value from another table

From Dev

Getting id values from a column and then get value from another table

From Dev

link a value from one table to another and slice one table based on columns from another table in sql

From Dev

FileMaker - Getting Data From Another Table with Multiple Field Restrictions

From Dev

Getting table rows in order of sum of count of two another columns from another table

From Dev

Sql server update multiple columns from another table

From Dev

Mysql Query for inserting from one table to another on Multiple conditions and columns

From Dev

MYSQL Import Column from another table matching multiple columns

From Dev

Concatenate A Row from columns of another table with multiple row

From Dev

Mysql Query for inserting from one table to another on Multiple conditions and columns

From Dev

Copying multiple columns from one SQL table to another

From Dev

MYSQL Import Column from another table matching multiple columns

From Dev

Join multiple columns to another table to return description from number

From Dev

select multiple columns from another table where field contains array

From Dev

How to extract multiple rows from a table based on values from multiple columns from another table and then concatenate in SQL?

From Dev

Getting a list value for every row (list of ids from another table)

From Dev

Getting the last value from a sequence in SQL and insert it into another table (Oracle)

From Dev

Getting rows that contain a value from another table SAS

From Dev

Getting one value from a table and assigning it to another with no repeats

From Dev

Getting a list value for every row (list of ids from another table)

From Dev

Optimize SQL Script: getting range value from another table

From Dev

Insert selected value to table from another table multiple times

Related Related

  1. 1

    LinqtoSQL Getting a value from another table

  2. 2

    Copy multiple columns from a table to another table with extra columns

  3. 3

    Fill multiple columns with value from another dataframe

  4. 4

    Update multiple columns of a table using aggregate values from another table

  5. 5

    Updating a table from another table with multiple columns in sqlalchemy

  6. 6

    Update multiple columns of a table using aggregate values from another table

  7. 7

    Display records from one table which is not in another table by multiple columns

  8. 8

    Update Table by getting maximum value from another table

  9. 9

    Getting id values from a column and then get value from another table

  10. 10

    link a value from one table to another and slice one table based on columns from another table in sql

  11. 11

    FileMaker - Getting Data From Another Table with Multiple Field Restrictions

  12. 12

    Getting table rows in order of sum of count of two another columns from another table

  13. 13

    Sql server update multiple columns from another table

  14. 14

    Mysql Query for inserting from one table to another on Multiple conditions and columns

  15. 15

    MYSQL Import Column from another table matching multiple columns

  16. 16

    Concatenate A Row from columns of another table with multiple row

  17. 17

    Mysql Query for inserting from one table to another on Multiple conditions and columns

  18. 18

    Copying multiple columns from one SQL table to another

  19. 19

    MYSQL Import Column from another table matching multiple columns

  20. 20

    Join multiple columns to another table to return description from number

  21. 21

    select multiple columns from another table where field contains array

  22. 22

    How to extract multiple rows from a table based on values from multiple columns from another table and then concatenate in SQL?

  23. 23

    Getting a list value for every row (list of ids from another table)

  24. 24

    Getting the last value from a sequence in SQL and insert it into another table (Oracle)

  25. 25

    Getting rows that contain a value from another table SAS

  26. 26

    Getting one value from a table and assigning it to another with no repeats

  27. 27

    Getting a list value for every row (list of ids from another table)

  28. 28

    Optimize SQL Script: getting range value from another table

  29. 29

    Insert selected value to table from another table multiple times

HotTag

Archive