Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting Usernames Uniquely

Suppose that I have a table with a column labeled Name, which contains (possibly) repeating entries of unique usernames. What LINQ-to-SQL statement can I write to uniquely traverse the usernames? In other words:

Here is an example of the table:

Name    Log
User1   05/13/13
User2   05/13/13
User2   05/14/13
User3   05/15/13
User1   05/15/13

I want to select usernames uniquely:

User1, User2, User3.

Thanks in advance!

like image 718
Junior Programmer Avatar asked Feb 10 '26 12:02

Junior Programmer


2 Answers

SELECT DISTINCT NAME FROM TABLE;

or in LinQ;

var names = Table.Select( t => t.Name ).Distinct().ToList();
like image 122
nvoigt Avatar answered Feb 13 '26 01:02

nvoigt


Create a linq query and use the .Distinct extension method on the result.
Example:

var users = (from logfile in logfiles select logfile.Name).Distinct();
like image 42
Mobius LSV Avatar answered Feb 13 '26 02:02

Mobius LSV



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!