duplicates

Prevent Duplicate SQL entries

谁都会走 提交于 2019-11-29 11:52:33
I want to be able to prevent duplicate SQL text field rows. That is, if row 1 has the name field already defined as "John Smith", I don't want it to be able to add another "John Smith" (as common as that name might be). I tried checking if it existed at time of insertion, but the problem is, if you open up two browser windows at the same time and click submit simultaneously, they'll both check, the check will clear, and then they'll both insert if it's close enough together. Oh, and this is on a PHP site. Thanks! CREATE UNIQUE INDEX idxname ON tablename (fieldname); Adding this index will

SQL Server : find duplicates in a table based on values in a single column

孤人 提交于 2019-11-29 11:33:21
I have a SQL Server table with the following fields and sample data: ID employeename 1 Jane 2 Peter 3 David 4 Jane 5 Peter 6 Jane The ID column has unique values for each row. The employeename column has duplicates. I want to be able to find duplicates based on the employeename column and list the ID s of the duplicates next to them separated by commas. Output expected for above sample data: employeename IDs Jane 1,4,6 Peter 2,5 There are other columns in the table that I do no want to consider for this query. Thanks for all your help! select employeename, IDs = STUFF((SELECT ','+ CAST(e2.[ID]

how do i insert multiple values in mysql and avoid duplicates

余生颓废 提交于 2019-11-29 11:32:31
How would I insert multiple rows or values and avoid duplicates in the following schema. table schema is id,subject1,subject2,subject3 id is auto incremented. A duplicate would be where all subject1,subject2,subject3 already exist in a record in the exact same order. INSERT INTO "table_name" ("subject1","subject2","subject3") VALUES ("cats", "dogs", "hamsters") VALUES ("squirrels", "badgers", "minxes") VALUES ("moose", "deer", "ocelots") In the table let's say I already have a record for id,subject1,subject2,subject3 1,"cats", "dogs", "hamsters" so I want it to just insert VALUES ("squirrels",

How to drop columns which have same values in all rows via pandas or spark dataframe?

帅比萌擦擦* 提交于 2019-11-29 11:02:21
问题 Suppose I've data similar to following: index id name value value2 value3 data1 val5 0 345 name1 1 99 23 3 66 1 12 name2 1 99 23 2 66 5 2 name6 1 99 23 7 66 How can we drop all those columns like ( value , value2 , value3 ) where all rows have same values, in one command or couple of commands using python ? Consider we have many columns similar to value , value2 , value3 ... value200 . Output: index id name data1 0 345 name1 3 1 12 name2 2 5 2 name6 7 回答1: What we can do is apply nunique to

Remove duplicated 2 columns permutations

好久不见. 提交于 2019-11-29 10:53:12
I can't find a good title for this question so feel free to edit it please. I have this data.frame section time to from 1 a 9 1 2 2 a 9 2 1 3 a 12 2 3 4 a 12 2 4 5 a 12 3 2 6 a 12 3 4 7 a 12 4 2 8 a 12 4 3 I want to remove duplicated rows that have the same to and from simultaneously, without computing permutations of the 2 columns: e.g (1,2) and (2,1) are duplicated. So final output would be: section time to from 1 a 9 1 2 3 a 12 2 3 4 a 12 2 4 6 a 12 3 4 I have a solution by constructing a new column key e.g key <- paste(min(to,from),max(to,from)) and remove duplicated key using duplicated ,

SQL Query - Delete duplicates if more than 3 dups?

£可爱£侵袭症+ 提交于 2019-11-29 10:49:44
Does anyone have an elegant sql statement to delete duplicate records from a table, but only if there are more than x number of duplicates? So it allows up to 2 or 3 duplicates, but that's it? Currently I have a select statement that does the following: delete table from table t left outer join ( select max(id) as rowid, dupcol1, dupcol2 from table group by dupcol1, dupcol2 ) as keeprows on t.id=keeprows.rowid where keeprows.rowid is null This works great. But now what I'd like to do is only delete those rows if they have more than say 2 duplicates. Thanks Remus Rusanu with cte as ( select row

How prevent duplicate items listView C#

那年仲夏 提交于 2019-11-29 10:41:10
I am using Windows Forms . With this code I add items to listView from comboBox . ListViewItem lvi = new ListViewItem(); lvi.Text = comboBox1.Text; lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add(""); lvi.SubItems.Add("") if (!listView1.Items.Contains(lvi)) { listView1.Items.Add(lvi); } I need prevent duplicate items but not work, How Can I solve this? You should be using ContainsKey(string key) instead of Contains(ListViewItem item) var txt = comboBox1.Text; if (!listView1.Items.ContainsKey(txt)) { lvi.Text = txt; // this is the key that ContainsKey uses. you might want to use

Sum duplicate row values

若如初见. 提交于 2019-11-29 09:32:22
问题 I'm trying to sum the values of rows two of which have duplicate values, the table I have is below: Table name (Customers) value years total 1 30 30 3 10 10 4 15 15 4 25 25 I would ideally like to finally have: value years total 1 30 30 3 10 10 4 40 40 I've tried using SELECT DISTINCT and GROUP BY to get rid of the duplicate row, also the join in the code below isn't necessary. Regardless both commands come to no avail. Here's my code too: SELECT DISTINCT value, years, SUM(customer.years) AS

How to detect duplicate words from a String in Java?

走远了吗. 提交于 2019-11-29 08:59:46
What are the ways by which duplicate word in a String can be detected? e.g. "this is a test message for duplicate test" contains one duplicate word test. Here, the objective is to detect all duplicate words which occur in a String. Use of regular expression is preferable to achieve the goal. The best you can do with regexes is O(N^2) search complexity. You can easily achieve O(N) time and space search complexity by splitting the input into words and using a HashSet to detect duplicates. The following Java code resolves the problem of detecting duplicates from a String. There should not be any

R finding duplicates in one column and collapsing in a second column

两盒软妹~` 提交于 2019-11-29 08:44:24
I have a data frame with two columns contacting character strings. in one column (named probes ) I have duplicated cases (that is, several cases with the same character string). for each case in probes I want to find all the cases containing the same string, and then merge the values of all the corresponding cases in the second column (named genes ) into a single case. for example, if I have this structure: probes genes 1 cg00050873 TSPY4 2 cg00061679 DAZ1 3 cg00061679 DAZ4 4 cg00061679 DAZ4 I want to change it to this structure: probes genes 1 cg00050873 TSPY4 2 cg00061679 DAZ1 DAZ4 DAZ4