0

I am trying to execute the following SQL statement using linq:

SELECT TTT.SomeField
FROM Table1 as T, Table2 as TT, Table3 as TTT
WHERE (T.NumberID = 100 OR T.NumberID = 101)
  AND T.QuestionID = 200
  AND T.ResponseID = TT.ResponseID
  AND TT.AnswerID = TTT.AnswerID

Essentially getting one field from a third table based on primary/foreign key relationships to the other 2 tables. It is expected to have a single result every time.

2
  • dotnetperls.com/join Commented Jun 28, 2013 at 14:35
  • Can you post examples of the 3 tables and the result you want out? Commented Jun 28, 2013 at 14:35

2 Answers 2

2
var query = from t in db.Table1
            join tt in db.Table2 on t.ResponseID equals tt.ResponseID
            join ttt in db.Table3 on tt.AnswerID equals ttt.AnswerID
            where (t.NumberID == 100 || t.NumberID == 101) && t.QuestionID == 200
            select ttt.SomeField

If you always expect single result, you can wrap this in ().Single(), or, if there might be no results found, in ().SingleOrDefault().

Sign up to request clarification or add additional context in comments.

1 Comment

sure thing! also I think he wants TTT.somefield. Not to be 'that guy'
0

If I understand you correct. You should read something about Joins I guess. here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.