[1] SELECT X.id FROM somwhere WHERE X.location = _stringReturnedFromC#_
// I need ID from this table, I only know strin: Location (from C#)
[2] SELECT Y.NameID FROM _relationBetweenXandY_ xy WHERE xy.ID = [1]
// I use the ID I just found in [1]
[3] SELECT Z.Name FROM Z WHERE Z.NameID = [2]
// I use the ID I found in [2]
Now how can I tell select [2] that I am looking for xy.ID = result from select [1]
And select [3] that I’m looking for the name of the guy with the ID Z.NameID
I asked this question here but as far as I’m concerned that question is beyond saving.
Z table:
Z.Name, Z.NameID
Y Table:
Y.PLACE, Y.PlaceID // fixed, Used to be PlaceID, is inface string: Place
X Table:
X.Name, X.PlaceID
If they have the same name, they are foreign keys (NameID, PlaceID)
This is how the actual code looks like:
SELECT * FROM Angajati a
JOIN Distribuire d ON d.Locatie = 'Oradea'
// now I need to get d.DistribuireID while I know d.Locatie (d.location). How ?
JOIN Angajari an ON d.DistribuireID = an.DistribuireID
Thus
SELECT *
FROM TableX X
JOIN TableY y on x.PlaceId = y.PlaceId
JOIN TableZ z on y.NameId = z.NameId
Does not work because I don’t know Y.PlaceID, I just know Y.Place
LAST EDIT
Sorry if this is getting too long. Here is how it should look like (what I mean by that, even if the syntax won’t work, this is the logic) Now I just need the syntax for this!
SELECT d.DistribuireID FROM Distribuire d WHERE d.Locatie = 'Oradea'
JOIN Angajari an ON an.DistribuireID = d.DistribuireID /*Here I'd need an.AngajatID for the locationID I just selected*/
JOIN Angajati a ON a.AngajatID = an.AngajatID
Looks like you just need some INNER JOINs:
Hope this helps.
-EDIT — Why won’t this work? Sorry if I’m not understanding your question…
Good luck.