0

I have multiple tables that have a userid guid field t hat is unique. I need to get a DISTINCT count of the userids of all all rows across all of these tables. I also need to access this count within a controller. How would I do this in entity framework? Or would it be better to use a stored procedure of some kind. Thanks.

1 Answer 1

0

How about using the UNION keyword?

SELECT guid FROM TABLE1
UNION
SELECT guid FROM TABLE2
UNION ....
SELECT guid FROM TABLEN 

Refer: http://www.w3schools.com/sql/sql_union.asp

Note that UNION always chooses distinct values. So, you should be good.

You can simply get the count using query nesting.

Select count(City) FROM
(SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City);
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, but how do I use this in a controller with the entity framework?

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.