What is SQL equivalent to LINQ.All ()

What would it look like in SQL (SQL Server if you want to be specific)?

// where people is a list of Person objects with property Name bool bobs = people.All(p => p.Name == "Bob"); 
+6
source share
2 answers

You would check if there are records that do not meet the criteria:

 not exists(select * from Persons where not Name = 'Bob') 

Since null comparison rules differ between C # and SQL, you will need a condition for null values ​​if the field allows them:

 not exists(select * from Persons where Name <> 'Bob' or Name is null) 
+5
source

I'm not sure which particular query will create Linq, but the equivalent in SQL is the ALL statement:

 'Bob' = ALL (SELECT name FROM people) 
+3
source

Source: https://habr.com/ru/post/981722/


All Articles