distinct

GROUP or DISTINCT after JOIN returns duplicates

橙三吉。 提交于 2019-12-18 09:16:12
问题 I have two tables, products and meta . They are in relation 1:N where each product row has at least one meta row via foreign key. (viz. SQLfiddle: http://sqlfiddle.com/#!15/c8f34/1) I need to join these two tables but i need to filter only unique products. When I try this query, everything is ok (4 rows returned): SELECT DISTINCT(product_id) FROM meta JOIN products ON products.id = meta.product_id but when I try to select all columns the DISTINCT rule no longer applies to results, as 8 rows

Distinct in SQL Server

巧了我就是萌 提交于 2019-12-18 09:14:48
问题 I am executing the following query, Select distinct a.cr_id, Case When ca.ca_vote = 'Approve' and ca.ca_title='MANAGER' Then ca.ca_email When ca.ca_vote = 'Reject' Then '' When ca.ca_vote = 'Pending' Then '' When ca.ca_vote = 'IN PROCESS' Then '' End as ca_email from credit a inner join credit_approvals ca on ca.c_id=a.cr_id where a.cr_cs_date between Convert(varchar(20),'11/16/2011',101) and dateadd(day,1,convert (varchar(20),'11/16/2011',101)) order by a.cr_id Despite distinct for cr_id ,

Distinct Values in WPF Combobox

跟風遠走 提交于 2019-12-18 09:08:15
问题 I would like to get distinct values in my databound combo box as an example the values it has are: blue, blue, yellow, red, orange I would like it to just display blue once. My main thought was to get all combo box values into an array, set the array as distinct and then re-populate the combo box. Is there any other way? If not how would I actually get all the values from the combo box? Thanks EDIT -- Class: public class DistinctConverter : IValueConverter { } EDIT -- Debug: 回答1: You could

Distinct list of lists, where lists contains same values but in different order

大憨熊 提交于 2019-12-18 05:55:58
问题 I got a list: var list = new List<List<int>>(); which could contain list[0] = {1, 2, 3, 4} list[1] = {3, 1, 2, 4} list[2] = {2, 1, 7, 3} How can I detect the duplicate between [0] and [1] and remove one of them? Code is c-sharp. In reality it's not a int, but that shouldn't change the question. 回答1: You could write your own implementation of IEqualityComparer<List<int>> . For GetHashCode() it would simply return the XOR of all the hash codes of the elements in the list. For Equals() it would

Removing duplicates from result of multiple join on tables with different columns in MySQL

浪尽此生 提交于 2019-12-18 05:07:13
问题 I am trying to make one statement to pull data from 3 related tables (as in they all share a common string index). I am having trouble preventing MySQL from returning the product of two of the tables, making the result set much larger than I want it. Each table has a different number of columns, and I would prefer to not use UNION anyway, because the data in each table is separate. Here is an example: Table X is the main table and has fields A B. Table Y has fields A C D. Table Z has fields A

Distinct pair of values SQL

让人想犯罪 __ 提交于 2019-12-17 22:17:22
问题 Consider create table pairs ( number a, number b ) Where the data is 1,1 1,1 1,1 2,4 2,4 3,2 3,2 5,1 Etc. What query gives me the distinct values the number column b has So I can see 1,1 5,1 2,4 3,2 only I've tried select distinct ( a ) , b from pairs group by b but gives me "not a group by expression" 回答1: What you mean is either SELECT DISTINCT a, b FROM pairs; or SELECT a, b FROM pairs GROUP BY a, b; 回答2: If you want to want to treat 1,2 and 2,1 as the same pair, then this will give you

How does Distinct() work?

时光毁灭记忆、已成空白 提交于 2019-12-17 21:06:28
问题 Lets say i have this: class Foo { public Guid id; public string description; } var list = new List<Foo>(); list.Add(new Foo() { id = Guid.Empty, description = "empty" }); list.Add(new Foo() { id = Guid.Empty, description = "empty" }); list.Add(new Foo() { id = Guid.NewGuid(), description = "notempty" }); list.Add(new Foo() { id = Guid.NewGuid(), description = "notempty2" }); Now, when i do this: list = list.Distinct().Tolist(); It obviously returns 4 elements. I would like a method, that

LINQ Distinct operator, ignore case?

孤街醉人 提交于 2019-12-17 17:54:34
问题 Given the following simple example: List<string> list = new List<string>() { "One", "Two", "Three", "three", "Four", "Five" }; CaseInsensitiveComparer ignoreCaseComparer = new CaseInsensitiveComparer(); var distinctList = list.Distinct(ignoreCaseComparer as IEqualityComparer<string>).ToList(); It appears the CaseInsensitiveComparer is not actually being used to do a case-insensitive comparison. In other words distinctList contains the same number of items as list . Instead I would expect, for

Linq Distinct() by name for populate a dropdown list with name and value

泪湿孤枕 提交于 2019-12-17 15:46:47
问题 I'm trying to populate a Drop down list with pharmaceutical companies, like Bayer, Medley etc. And, I'm getting theses names from DB and theses names are repeated in DB, but with different id's. I'm trying to use Linq Distinct(), but I don't want to use the equality comparer. Is there another way? My drop down list must be filled with the id and the name of the company. I'm trying something like: var x = _partnerService .SelectPartners() .Select(c => new {codPartner = c.codPartner, name = c

linq distinct or group by multiple properties

只谈情不闲聊 提交于 2019-12-17 15:46:46
问题 How can I using c# and Linq to get a result from the next list: var pr = new List<Product>() { new Product() {Title="Boots",Color="Red", Price=1}, new Product() {Title="Boots",Color="Green", Price=1}, new Product() {Title="Boots",Color="Black", Price=2}, new Product() {Title="Sword",Color="Gray", Price=2}, new Product() {Title="Sword",Color="Green",Price=2} }; Result : {Title="Boots",Color="Red", Price=1}, {Title="Boots",Color="Black", Price=2}, {Title="Sword",Color="Gray", Price=2} I know