Gary Czychi Gary Czychi - 10 months ago 73
SQL Question

Combining two nested SELECT with DISTINCT?

How do I look up DISTINCT values of one table, look for each name in another table and get both the values and their names as a result?

The Beleg table looks like this:

SELECT DISTINCT Ursprungskonto FROM Beleg
WHERE YEAR ( Valuta ) = 2016

gets me:


For each of these values, I need to lookup its name:

SELECT Name FROM Geldkonto
WHERE Kontonr = 1000

results in:


At the end of the query, I need to have this result:

1000 Kasse
1210 OneBankName
1220 AnotherBankName
1230 YABN

I'm using SQL-92 (Filemaker).

Thanks a lot for any help!


You could use inner join

SELECT DISTINCT Beleg.Ursprungskonto, Geldkonto.Name 
FROM Beleg 
INNER JOIN Geldkonto
ON Beleg.Ursprungskonto=Geldkonto.Kontonr;