| Author |
Topic |
|
forevercalz
Starting Member
5 Posts |
Posted - 2005-11-17 : 04:10:56
|
| Hi i have this variable called order1 in the table called datetable and i want to display out the duplicate orders in sql. how do i do that? do i need to use group by ?thanks in advance.! any help?well i actually get the answers by doin this...select order1 from datetable group by order1 having count(*) > 1however now i want to compare the values date1 in the first duplicate orders to the second duplicate order...like compare aaaa of the first row and aaaa of the second row ...how to do that? i need to compare the date1 in minutes..i only wan duplicate orders with minutes difference less than 30minsegid Order1 date11 aaaaa 20051001 12:45 2 aaaaa 20051001 12:103 bbbbb 20031002 15:054 bbbbb 20031002 15:50 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-17 : 04:41:50
|
| Try thisSelect t1.id,t1.order1 from yourTable t1 inner join yourTable t2 on t1.id<t2.idwhere t1.order1=T2.order1 and datediff(minute,t1.date1,t2.date1)<30MadhivananFailing to plan is Planning to fail |
 |
|
|
forevercalz
Starting Member
5 Posts |
Posted - 2005-11-17 : 05:08:00
|
| the problem is i only have one table. The duplicated records are from one table only.how to inner join? inner the same table? |
 |
|
|
surendrakalekar
Posting Yak Master
120 Posts |
Posted - 2005-11-17 : 05:18:00
|
quote: Originally posted by forevercalz the problem is i only have one table. The duplicated records are from one table only.how to inner join? inner the same table?
Yes user the same table in both the places.Surendra |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-11-17 : 05:31:04
|
| [code]Select t1.id,t1.order1 from datetable t1 inner join datetable t2 on t1.id < t2.idwhere t1.order1 = t2.order1 and datediff(minute, t1.date1, t2.date1) < 30[/code][KH] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-17 : 05:42:19
|
quote: Originally posted by forevercalz the problem is i only have one table. The duplicated records are from one table only.how to inner join? inner the same table?
In that query replace yourTable by the actual table name. You dont need to use two tables MadhivananFailing to plan is Planning to fail |
 |
|
|
forevercalz
Starting Member
5 Posts |
Posted - 2005-11-17 : 19:55:36
|
| ok ...however now i need to remove the id..so i enter the following code:Select t1.order1from datetable t1 inner join datetable t2where t1.order1 = t2.order1and datediff(minute, t1.date1, t2.date1) < 30and i have this error:SQL command not properly endedi need to get this output:ORDER1 DATE1---------- --------------aaaaa 20051001 12:45aaaaa 20051001 12:20i doin it in oracle sql... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-17 : 23:21:48
|
| >>i doin it in oracle sql...This is SQL Server Forum. If you are using Oracle post your question at www.DBForums.comMadhivananFailing to plan is Planning to fail |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2005-11-18 : 00:29:03
|
| Yes. Microsoft SQL Server Forum[KH] |
 |
|
|
forevercalz
Starting Member
5 Posts |
Posted - 2005-11-18 : 01:51:08
|
| ok..thanks for you help !! you guys are friendly.. |
 |
|
|
|