Solved

SQL Query error

Posted on 2009-05-08
10
184 Views
Last Modified: 2012-05-06
Attempting to delete rows with duplicate fields using this query:

Delete FROM TEMP_PROP t1 CROSS JOIN TEMP_PROP t2
where t1.RowID <> t2.RowID
and t1.situs_dpbc = t2.situs_dpbc

I received this error:
Line 1: Incorrect syntax near 't1'.
0
Comment
Question by:marknicks
  • 4
  • 3
  • 3
10 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 300 total points
Comment Utility
Delete TEMP_PROP
FROM TEMP_PROP t1 CROSS JOIN TEMP_PROP t2
where t1.RowID <> t2.RowID
and t1.situs_dpbc = t2.situs_dpbc
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
I presume you want this:
Delete FROM TEMP_PROP t1 
WHERE EXISTS ( SELECT NULL FROM TEMP_PROP t2 
           where t1.RowID <> t2.RowID
             and t1.situs_dpbc = t2.situs_dpbc
              )

Open in new window

0
 

Author Comment

by:marknicks
Comment Utility
Thanks for a quick response.  Unfortunately we haven't found it yet.

The first answer gave this error:
The table 'temp_prop' is ambiguous.

The second gave this error:
Line 1: Incorrect syntax near 't1'.
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
Comment Utility
correction for mine:
Delete TEMP_PROP t1 

WHERE EXISTS ( SELECT NULL FROM TEMP_PROP t2 

           where t1.RowID <> t2.RowID

             and t1.situs_dpbc = t2.situs_dpbc

              )

Open in new window

0
 

Author Comment

by:marknicks
Comment Utility
still getting the syntax error near t1
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 300 total points
Comment Utility

Delete TEMP_PROP
from TEMP_PROP t1
WHERE EXISTS ( SELECT NULL FROM TEMP_PROP t2
           where t1.RowID <> t2.RowID
             and t1.situs_dpbc = t2.situs_dpbc
              )
0
 
LVL 142

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 200 total points
Comment Utility
I guess that's still not correct :/
Delete t1

FROM TEMP_PROP t1 

WHERE EXISTS ( SELECT NULL FROM TEMP_PROP t2 

           where t1.RowID <> t2.RowID

             and t1.situs_dpbc = t2.situs_dpbc

              )

Open in new window

0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 300 total points
Comment Utility
@Angel

I think thta should work, try this example

declare @tab1 table ( i int )
insert into @tab1 select 1
insert into @tab1 select 2
insert into @tab1 select 3
declare @tab2 table ( i int )
insert into @tab2 select 1
insert into @tab2 select 6


delete  @tab1
from @tab1 t1
where exists (SELECT 1 from @tab2 t2 where t1.i = t2.i )

select * from @tab1

 
0
 

Author Comment

by:marknicks
Comment Utility
well it at least ran without errors.  but i'm still testing.
I think it's pretty close to the right solution.
0
 

Author Closing Comment

by:marknicks
Comment Utility
This series of queries turned out to be the best approach, elminating the FoxPro routines.

"select * into #Temp_Dups from Temp_Prop
      where (rowid in (select MIN(rowid) as min_id from temp_prop
            group by mailing_zip, mailing_addr_line1
              having count(*) > 1)) AND (Session_ID = '" & strSession_ID & "')"

"Delete temp_prop from TEMP_PROP t1
      WHERE (EXISTS ( SELECT NULL FROM TEMP_PROP t2 where(t1.rowid <> t2.rowid)
        and t1.mailing_zip + t1.mailing_addr_line1 = t2.mailing_zip + t2.mailing_addr_line1))
        AND (Session_ID = '" & strSession_ID & "')"

"alter table #Temp_Dups drop column rowid"

"insert Temp_Prop select * from #Temp_Dups"

I appreciate all your comments as they pointed me in the right direction!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now