0

The question is: "Get all employees from department 10 which have a job which is also practiced in dept 30"

I want to do it in the non-ExtensionMethod format - like:

from e in emp
select e;

I tried something like that

var x =
    from e in emp
    where e.deptno == 10 && e.job == (from e2 in scott.emp
                                      where e2.deptno == 30
                                      select e2.job)
    select e;

which just makes sense that it doesn't work because i can't compare string with IEnumerable

So how can I solve this?

AutMai
  • 187
  • 4
  • 18
  • 1
    Use a [join](https://learn.microsoft.com/en-us/dotnet/csharp/linq/perform-inner-joins)? – Heretic Monkey Apr 28 '21 at 15:19
  • @HereticMonkey and what condition would i use? – AutMai Apr 28 '21 at 15:21
  • @HereticMonkey i just have 1 table should i join from employees to employees? – AutMai Apr 28 '21 at 15:25
  • 1
    You would join `emp` to `emp` on `job` and have one table limited to `deptno == 10` and the other to `deptno == 30`. I mean, this is just how I would think about it. – Heretic Monkey Apr 28 '21 at 15:25
  • So `where e.deptno == 10` then `join e2 in emp on e.job equals e2.job` and finally `where e2.deptno == 30` ? – AutMai Apr 28 '21 at 15:31
  • Well if that's your idea, why not try it and see? – ADyson Apr 28 '21 at 15:36
  • Alternatively with the query in your question, with the `e.job == (from`, the equals should be an `IN` clause (in standard SQL) - I think you express it a bit differently in linq though - try the suggestions at https://stackoverflow.com/questions/3047657/linq-to-sql-in-and-not-in perhaps – ADyson Apr 28 '21 at 15:39
  • Just join, don't try and conditionally join. – Heretic Monkey Apr 28 '21 at 15:40

0 Answers0