Mafklaper
Mafklaper

Reputation: 43

SQL how to select a column from a foreign key without join

I hope you guys can help me. I have 2 tables 1 called Stuk and one is called Niveau.

In the table Stuk I have a FK from the table Niveau. This is the column niveaucode the skill codes I have are:

A EXAMPLE 1
B EXAMPLE 2
C EXAMPLE 3

If I select a musicpiece I don't want to see A, B or C I want to see EXAMPLE 1, EXAMPLE 2 or EXAMPLE 3. I have to do this without a JOIN

enter code here

Upvotes: 0

Views: 730

Answers (2)

Sergey
Sergey

Reputation: 5225

SELECT S.[stuknr], S.[genrenaam],
CASE
  WHEN S.niveaucode='A' THEN 'EXAMPLE 1' 
  WHEN S.niveaucode='B' THEN 'EXAMPLE 2'
  WHEN S.niveaucode='C' THEN 'EXAMPLE 3'
  ELSE 'HMM'
END AS FLAG
FROM dbo.Stuk S 
WHERE  S.[jaartal] > 1995

Upvotes: 1

tnavidi
tnavidi

Reputation: 1418

I guess this will answer your question:

select stuknr, componistid, titel, stuknrorigineel, genrenaam, omskrijving, speeldur, jaartal 
from stuk a, niveau b where a.niveaukode = b.niveaukode

Sorry if I misspelled any of your attributes (I didn't double check, and I don't know dutch)

Upvotes: 0

Related Questions