Dr.Kameleon
Dr.Kameleon

Reputation: 22820

Combine Table Results in a Relational Database

OK, first-off let me make this clear : I'm very weak with SQL and Databases (I mean apart from several simple statements), but it turns out I have to deal with some SQLite DBs, so I guess I need your help on this query (which should be ultra-simple simple for anyone more familiar with SQL than me...):

I have 2 tables :

TOKENTYPES

TOKENTYPE_ID  TOKENTYPE_NAME
1             nameA
2             nameB
3             nameC

TOKENS

TOKEN_ID TOKENTYPE_ID TOKEN_NAME
1        2            tokA
2        2            tokB
3        3            tokC

What I know :

Now, here's the catch :

How can I sort-of "combine" these 2 queries and get a table with TOKENTYPE_NAME, TOKEN_NAME?


EDIT:

Desired Result :

TOKEN_NAME TOKENTYPE_NAME

tokA       nameB
tokB       nameB
tokC       nameC

Upvotes: 0

Views: 54

Answers (2)

John Woo
John Woo

Reputation: 263723

SELECT  a.Token_Name,
        b.TokenType_Name
FROM    Tokens  a
        INNER JOIN TokenTypes b
            ON a.TokenType_ID = b.TokenType_ID

To further gain more knowledge about joins, kindly visit the link below:

RESULT

╔════════════╦════════════════╗
║ TOKEN_NAME ║ TOKENTYPE_NAME ║
╠════════════╬════════════════╣
║ tokA       ║ nameB          ║
║ tokB       ║ nameB          ║
║ tokC       ║ nameC          ║
╚════════════╩════════════════╝

Upvotes: 1

JodyT
JodyT

Reputation: 4412

SELECT tt.TOKENTYPE_NAME, t.TOKEN_NAME 
FROM TOKENS AS t
JOIN TOKENTYPES AS tt
    ON tt.TOKENTYPE_ID = t.TOKENTYPE_ID

Upvotes: 1

Related Questions