Reputation: 22820
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 :
SELECT TOKENTYPE_ID,TOKEN_NAME FROM TOKENS
, I can get all (TOKENTYPE_ID,TOKEN_NAME) pairs from TOKENSSELECT TOKENTYPE_NAME FROM TOKENTYPES WHERE TOKENTYPE_ID=2
, I can get the Name
for a specific token ID.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
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
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