distinct

How do I remove duplicates in an SQL query without using Distinct?

拟墨画扇 提交于 2019-12-11 05:08:13
问题 There are duplicates in the results of the query below. My question is how to get rid of subTaskName duplicates without using distinct ? SELECT tasks.priority, (SELECT tasks.name FROM tasks WHERE tasks.taskid ='11377') AS taskName, tasks.name AS subTaskName,u.name,tasks.deadline,tasks.created,a.duration AS durata,tasks.parentID,tasks.userid ,tasks.finished, tasks.estimated,tasks.taskid,tasks.section,tasks.tags FROM tasks INNER JOIN users u ON tasks.assignerid = u.userid INNER JOIN activities

SELECT DISTINCT Cassandra in Spark

眉间皱痕 提交于 2019-12-11 05:03:04
问题 I need a query that lists out the the unique Composite Partition Keys inside of spark. The query in CASSANDRA: SELECT DISTINCT key1, key2, key3 FROM schema.table; is quite fast, however putting the same sort of data filter in a RDD or spark.sql retrieves results incredibly slowly in comparison. e.g. ---- SPARK ---- var t1 = sc.cassandraTable("schema","table").select("key1", "key2", "key3").distinct() var t2 = spark.sql("SELECT DISTINCT key1, key2, key3 FROM schema.table") t1.count // takes 20

Translate SQL command to Nhibernate Linq using Criteria or QueryOver - Count results of ditinct selected columns

笑着哭i 提交于 2019-12-11 04:50:11
问题 I'm trying to translate the following SQL statement into Nhibernate query using Criteria or QueryOver but it's not working!! the SQL command is: select Count(*) from ( select distinct col1, col2, col3 from tableName where col1 like '%t%' or col4 like '%t%' ) As x It either counts the results were's no projection applied, or it gives me a run-time error regards using this query.SetProjection(Projections.Count(Projections.Distinct( Projections.ProjectionList() .Add(Projections.Property("col1"))

Why does DISTINCT has to go first in MySQL?

最后都变了- 提交于 2019-12-11 04:43:06
问题 I have a query that works when I do SELECT DISTINCT(table.field.id), 1 FROM ... but fails when I do SELECT 1, DISTINCT(table.field.id) FROM ... Is this a known behavior? Why does the first one work while the second doesn't? 回答1: Unfortunately I'm not able to add a comment yet. What @Gordon Linoff has written is exactly right. You are getting error as DISTINCT in general works as part of SELECT clause or AGGREGATE function. It is used to return unique rows from a result set and it can be used

sql join - only select top row from 2nd table

こ雲淡風輕ζ 提交于 2019-12-11 04:39:50
问题 Bit of an sql noob, have a list in table a of customercodes/phone numbers, and table b has all the call records. I want to select the most recent call from table b for each of the customercodes/phone numbers in table a. So far I have: SELECT A.CustomerCode, A.PhoneNumber, B.StartTime FROM tableA A INNER JOIN tableB B ON ( A.PhoneNumber = B.PhoneNumber AND A.CustomerCode = B.CustomerCode ) ORDER BY A.CustomerCode, A.CLI, B.StartTime DESC But that is bringing up all the results from TableB. I

Select a subgroup of records by one distinct column

半世苍凉 提交于 2019-12-11 04:32:22
问题 Sorry if this has been answered before, but all the related questions didn't quite seem to match my purpose. I have a table that looks like the following: ID POSS_PHONE CELL_FLAG ======================= 1 111-111-1111 0 2 222-222-2222 0 2 333-333-3333 1 3 444-444-4444 1 I want to select only distinct ID values for an insert, but I don't care which specific ID gets pulled out of the duplicates. For Example(a valid SELECT would be): 1 111-111-1111 0 2 222-222-2222 0 3 444-444-4444 1 Before I

Selecting the distinct values from three columns with the max of a fourth where there are duplicates

自古美人都是妖i 提交于 2019-12-11 04:29:22
问题 I have a table with one numeric value (n) and three string values (a,b,c). How do I query this table so that I get only distinct values of (a,b,c) and if there are duplicates, take the maximum of the corresponding set of n values? 回答1: select max(n), a, b, c from mytable group by a, b, c 回答2: Use GROUP BY : select a, b, c, max(n) from table group by a, b, c; This will show only unique or distinct sets of a, b, c and show the maximum n found in that set. MAX is an aggregate function designed

Selecting distinct values from two tables

时光总嘲笑我的痴心妄想 提交于 2019-12-11 04:06:30
问题 I have two rather large databases (+1 million rows each). Both tables have the same structure. How can I check if each value in a column is unique across both tables? Is there a SELECT COUNT(DISTINCT col ) FROM tbl type of query that will consider BOTH tables? Thanks! 回答1: You can UNION two full sets in a subquery and then select DISTINCT col from that. Something like: SELECT DISTINCT col FROM (SELECT * FROM tbl1 UNION ALL SELECT * FROM tbl2) 回答2: You can use UNION ALL statement. It doesn't

MS ACCESS count/sum number of rows, with no duplicates

。_饼干妹妹 提交于 2019-12-11 03:51:57
问题 I have the following table which I need to count the total number of rows without including any duplicate records. CustomerID test1 test1 test2 test3 test4 test4 As you can see, the total number of rows is 6 but there are two test1 and two test4, and I wish the query to return 4. IOW, I want to count unique values in CustomerID . I've tried sub query but didn't get it to work for me. -- Update 27/06/2012 -- Thanks, both worked for me: SELECT COUNT(*) FROM ( SELECT CustomerID FROM TheTable

Alternative to SELECT DISTINCT

馋奶兔 提交于 2019-12-11 03:27:35
问题 I'm not too familiar with SQL queries but have noticed a significant performance decrease when running a query using Select Distinct. I'm running SQL Server 2008 R2. Below is my query: select distinct CL.ClientID, NL.Name from CL CL inner join PR PR on CL.ClientID = PR.ClientID where PR.WBT1 in (Select distinct WBT1 from TabFields where custInclude = 'Y' and WBT2 = '') and PR.WBT2 = '' order by NL.Name Does anyone know how to revise this query without using select distinct in order to speed