distinct

options for returning distinct values across an inner join

妖精的绣舞 提交于 2019-12-12 01:46:01
问题 I have two tables. Table A contains UserID, UserName Table B contains ID, FK_UserID, ClientName I need to return a list of distinct A.UserName where A.Username exists in table B and has at least one ClientName attached to them, but in my query, only look at distinct B.ClientName. My thoughts were: Select Distinct A.UserName from A as A Inner Join B as B on A.UserID = B.FK_UserID But that only distincts on table A My next thought was: Select Distinct Username from A where UserID In ( Select FK

Entity Framework query - return unique rows from child table

老子叫甜甜 提交于 2019-12-12 01:38:42
问题 I have Entity Framework model as below and data in the corresponding database tables: Question: How do I query the model for returning all the rows (full entities, not anonymous type) from sales_type relevant to a given person ? If the data is as above, then for John, the query should return first three rows from sales_type -table and for Mark it should return the rows 2 and 5. 回答1: Something like this ctx.PersonSales .Where(ps=> ps.Person.Id = myPersonId) .Where(ps=> ps.SalesMapping != null

Sql SELECT DISTINCT - How can I select distinct couple without considering columns' order?

烂漫一生 提交于 2019-12-12 01:27:52
问题 I have a table like this ID | Sender | Receiver 0 | EmailA | EmailB 1 | EmailB | EmailA 2 | EmailA | EmailB 3 | EmailA | EmailC 4 | EmailC | EmailA ... and I want to select only the couples in which A is. I mean, I want the rows: 0 | EmailA | EmailB 1 | EmailA | EmailC I don't care if I'll get 0 | EmailA | EmailB or 1 | EmailB | EmailA because in my case A,B is the same as B,A but I need it only once. I saw many answers to questions like this but I can't solve my problem. Thank you very much.

Does mongoose's “distinct” function support regex in a query?

▼魔方 西西 提交于 2019-12-12 01:12:05
问题 I have the following bit of js in a node/mongoose project. I'm working on an autocomplete form. It works just fine with a regular "find", but I want to do a "distinct" find instead. So here's where I'm at so far. The problem I believe is in the way the query is formed. Can someone help with my syntax in the distinct line? Or is it just that mongoose's "distinct" doesn't support regex in an optional query? var text.term = 'johnny'; var regex = new RegExp("^"+text.term); // execute the search

SELECT Unique rows from Datagridview using LINQ

穿精又带淫゛_ 提交于 2019-12-12 00:27:48
问题 I am trying to SELECT ALL rows\columns from a datagridview where the first column is unique using LINQ. Datagridview: 1 Blue 1111 1 Blue 1111 2 Green 1234 3 Orange 3211 2 Green 1234 4 Red 2222 Trying to get this Output: 1 Blue 1111 2 Green 1234 3 Orange 3211 4 Red 2222 I was able to use the following code which pulls all unique records from the first column but I am not sure how to get the remaining columns: Dim unique() As String = (From row As DataGridViewRow In dgvMaestro.Rows.Cast(Of

SELECT DISTINCT on multiple columns along with other columns [duplicate]

隐身守侯 提交于 2019-12-11 23:21:04
问题 This question already has answers here : How do I (or can I) SELECT DISTINCT on multiple columns? (5 answers) Closed 4 years ago . I want to run query like below select distinct (columnA, columnB, columnC), columnD from MY_TABLE where columnA IS NOT NULL AND columnB IS NOT NULL AND columnC is NOT NULL; I only want distinct of columnA, columnB and columnC and NOT ON columnD. But SQL developer is pointing an error right after columnA, How can I fix this? I tried to fix my query using GROUP BY

Why I got incorrect calculation of COUNT DISTINCT with GROUP BY?

限于喜欢 提交于 2019-12-11 23:11:45
问题 I have a table INTERACTIONS CustomerID | Channel | Response -----------+---------+---------- 245 | SMS | Accept 245 | PUSH | Ignore 247 | SMS | Accept 249 | PUSH | Ignore When I make request SELECT COUNT(DISTINCT CUSTOMERID) AS Customers FROM INTERACTIONS; I get result 7440 When I make query with group by Channel, and then calculate sum for all groups: SELECT SUM(CUSTOMERS) FROM (SELECT CHANNEL, COUNT(DISTINCT CUSTOMERID) AS Customers FROM INTERACTIONS GROUP BY CHANNEL); I get result 9993 Why

Count in sequential order

旧街凉风 提交于 2019-12-11 22:05:27
问题 I have a data set that has a list of id's and with those id's are a list of categories (so each id may have many categories). I want to search a list of categories and see how many different id's are within that category (count) but once a id is counted in one category it will not be counted in another. Example: ID Category 1 Gas Station 1 Convenience Store 1 Barber 2 Day Care 2 Gas station 3 Convenience Store 3 Golf Range So if I am doing a search of counts on gas station and convenience

How to get rows for n distinct values of a column

▼魔方 西西 提交于 2019-12-11 21:14:41
问题 I need to get rows for n distinct invoice numbers. I have SELECT query that gives me results from the table: SELECT A.INVOICE_NUMBER, A.INVOICE_SEQ_NUMBER, B.FILE_NUMBER FROM TABLE1 AS A, TABLE2 AS B WHERE A.INVOICE_NUMBER = B.INVOICE_NUMBER AND A.INVOICE_SEQ_NUMBER = B.INVOICE_SEQ_NUMBER So I get this as a result of my query: ----------------------------------------------------- | INVOICE_NUMBER | INVOICE_SEQ_NUMBER | FILE_NUMBER | ------------------------------------------------------

Confusion about SELECT DISTINCT in SQL

谁说我不能喝 提交于 2019-12-11 19:21:19
问题 When I select COLUMN_1 only I get the right amount of 8 rows in my database because it doesn't give me duplicate rows and its what I want SELECT DISTINCT COLUMN_1 FROM TABLE WHERE COLUMN_3=12; but when select both COLUMN_1, COLUMN_2 it gives me 53 rows in my database and that's not what I want... SELECT DISTINCT COLUMN_1,COLUMN_2 FROM TABLE WHERE COLUMN_3=12; I know when I select two columns with distinct , it will give me unique values for the combination of the two columns. DISTINCT is