473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

crazy statement :) please help

Hi all,
This is my first time... and i'm not an sql guy by any means, but i can insert, update, blah blah...
I have a question to ask, i have a table that has
UniqueInt | Date1 | int1 | Date2 | varchar 1

I have duplicate records that i need to delete and i need to write an sql statement.

it goes like this,

UniqueInt | Date1 | int1 | Date2 | varchar 1
1 | 1/1/2008 10:00:00 am | 1 | 12/15/2007 10:00:00 am| 123456
2 | 1/1/2008 10:00:00 am | 1 | 12/15/2007 10:30:00 am| 123456

delete the first record where int1 =1 and varchar1 is the same and the difference between date2 is less than 1 minute.

Is that possible?

Thanks in advance
Jan 29 '08 #1
4 1257
Delerna
1,134 Expert 1GB
is something like this what you are after

Expand|Select|Wrap|Line Numbers
  1. DELETE 
  2. FROM TableName 
  3. WHERE DATEDIFF(mi,Date1,Date2)<1
  4.  
hope it helped
Jan 30 '08 #2
is something like this what you are after

Expand|Select|Wrap|Line Numbers
  1. DELETE 
  2. FROM TableName 
  3. WHERE DATEDIFF(mi,Date1,Date2)<1
  4.  
hope it helped
Thanks Delerna,
here you are comparing date1 and date2, what i need is to compare date2 from one record and date 2 from another record.
Jan 30 '08 #3
ck9663
2,878 Expert 2GB
Hi all,
This is my first time... and i'm not an sql guy by any means, but i can insert, update, blah blah...
I have a question to ask, i have a table that has
UniqueInt | Date1 | int1 | Date2 | varchar 1

I have duplicate records that i need to delete and i need to write an sql statement.

it goes like this,

UniqueInt | Date1 | int1 | Date2 | varchar 1
1 | 1/1/2008 10:00:00 am | 1 | 12/15/2007 10:00:00 am| 123456
2 | 1/1/2008 10:00:00 am | 1 | 12/15/2007 10:30:00 am| 123456

delete the first record where int1 =1 and varchar1 is the same and the difference between date2 is less than 1 minute.

Is that possible?

Thanks in advance
assumption: there are only two records. if this assumption is wrong, this query will not work:

1. add a new column on your table C(1)
2. update mytable
set newcolumn = '1'
from
(select varchar1, mindate
(select varchar1, min(Date2) as mindate from yourtable where int1 = 1 group by varchar1 ) FirstRow inner join
(select varchar1, max(Date2) as maxdate from yourtable where int1 = 1 group by varchar1 ) SecondRow on FirstRow.varchar1 = SecondRow.varchar1
where abs(datediff(mi, mindate, maxdate)) < 1) summary
where mytable.varchar1 = summary.varchar1 and mytable.date2 = summary.mindate and int1 = 1

3. select * from mytable where newcolumn = '1'. inspect if you flag the right rows.
4. delete from mytable where newcolumn = '1'

you did this because if your query failed, you might delete the wrong row and you don't have a backup table. if you have to rerun your query, you have to replace back all fields to NULL or '0' to reset it.

-- ck
Jan 30 '08 #4
ck9663
2,878 Expert 2GB
and by the way, there's always cursor

-- ck
Jan 30 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: doltharz | last post by:
Please Help me i'm doing something i though was to be REALLY EASY but it drives me crazy The complete code is at the end of the email (i mean newsgroup article), i always use Option...
4
by: fowlertrainer | last post by:
Hi ! I want to get the WMI infos from Windows machines. I use Py from HU (iso-8859-2) charset. Then I wrote some utility for it, because I want to write it to an XML file. def...
0
by: JackJian | last post by:
Hi guys, I have developed a MDI windows application with C# on my desktop box (1024*768), lately I load my code into my laptop to do the improvement, the resolution of the laptop is 1680*1050,...
3
by: Allan | last post by:
Please help, below is my problem. Let's say I have 2 tables, a Products table and a Colors table that go as follow: Table Products prodID Name 1 shirt 2 tshirt
19
by: Daniel Billingsley | last post by:
I think it's really nice to be able to do code like someVariable = someMethod(new SomeClass("some text")); However, as method signatures are number and types of parameters, you're limited to...
1
by: Joe Blanchard via .NET 247 | last post by:
Hello, Can someone please help me. I thought this would be simple but so far nothing I try works..... I've got a simple update page. On this page I have a datalist bound by data from a SQL...
0
by: Aws | last post by:
My crazy GridView !! I am using Visual Studio 2005, I have a problem with my GridView. I have one access .mdb table and when I update a record on the table EVERYTHING is perfect. I made a Web...
5
by: Pupeno | last post by:
Hello, I am experiencing a weird behavior that is driving me crazy. I have module called Sensors containing, among other things: class Manager: def getStatus(self): print "getStatus(self=%s)"...
5
by: mark4asp | last post by:
Every time the function below is called I get the alert. So I put a deliberate error in there and I check the value of (reportType=='MANDATE') in Firebug, which is found to be true. But still the...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.