473,386 Members | 1,795 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,386 software developers and data experts.

delete syntax

I am performing deleting action but getting the error
Incorrect syntax near ','


delete from table1a
where (a.col1,a.col2,a.col3,a.col4) not in
(select b.col1,b.col2,b.col3,b.col4
from table2 b)

Here table 1 and table 2 are similar in structure but in diff databases and col1,col2,col3,col4 together form the primary key.
Mar 21 '07 #1
8 5930
iburyak
1,017 Expert 512MB
Try this:


[PHP]
Delete from table1 a
where NOT EXISTS (select *
from table2 b
where b.col1 = a.col1 and b.col2 = a.col2 and b.col3 = a.col3 and b.col4 = a.col4)[/PHP]
Mar 21 '07 #2
Hi i tried that code..but it is giving error at first line
Incorrect syntax near 'a'.
Mar 21 '07 #3
iburyak
1,017 Expert 512MB
Try to do this:

[PHP]
Delete from table1 from table1 a
where NOT EXISTS (select *
from table2 b
where b.col1 = a.col1 and b.col2 = a.col2 and b.col3 = a.col3 and b.col4 = a.col4)

[/PHP]
Mar 21 '07 #4
iburyak
1,017 Expert 512MB
I would suggest running below statement firs just to be sure correct records will be deleted if it is a production table.

[PHP]Select *
from table1 a
where NOT EXISTS (select *
from table2 b
where b.col1 = a.col1 and b.col2 = a.col2 and b.col3 = a.col3 and b.col4 = a.col4) [/PHP]
Mar 21 '07 #5
Hi...it worked out...gr8

But the syntax sounds strange..Cam u explain me more abt this syntax


Delete from table1 from table1 a
Mar 21 '07 #6
iburyak
1,017 Expert 512MB
This is exact syntax from SQL help:

[PHP]DELETE
[ FROM ]
{ table_name WITH ( < table_hint_limited > [ ...n ] )
| view_name
| rowset_function_limited
}

[ FROM { < table_source > } [ ,...n ] ]

[ WHERE
{ < search_condition >
| { [ CURRENT OF
{ { [ GLOBAL ] cursor_name }
| cursor_variable_name
}
] }
}
]
[ OPTION ( < query_hint > [ ,...n ] ) ] [/PHP]

First “From” tells SQL from which table to delete and is optional.
Second “From” is used in cases when you need a join or alias for a table name that happened to be the same one as deleted table.

Example:
[PHP]DELETE titleauthor
FROM titleauthor INNER JOIN titles
ON titleauthor.title_id = titles.title_id
WHERE titles.title LIKE '%computers%'[/PHP]

Hope it helps. I am not very good with explanations .... :)

Irina.
Mar 21 '07 #7
Thanx for ur time dude..

In fact u r very good at explanation....
Mar 21 '07 #8
Hi,

Just like delete, i want to perform insert operation.
Delete from table1 from table1 a
where NOT EXISTS (select *
from table2 b
where b.col1 = a.col1 and b.col2 = a.col2 and b.col3 = a.col3 and b.col4 = a.col4)

I tried as but gives error at 'from'.What is the correct syntax

insert into table1 from table1 a
where NOT EXISTS (select *
from table2 b
where b.col1 = a.col1 and b.col2 = a.col2 and b.col3 = a.col3 and b.col4 = a.col4)

--------------------------------------------------------------------------------
Mar 22 '07 #9

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

Similar topics

4
by: Scotter | last post by:
Hi folx - Here is the code I'm trying (but it errors out with "Item cannot be found in the collection corresponding to the requested name or ordinal."): ...
5
by: Mike | last post by:
I am not a sql person and could use some help with a delete...here is what I want: I have the following tables/fields (only including necessary fields) answers result_id results result_id
1
by: Nimmi Srivastav | last post by:
There's a rather nondescript book called "Using Borland C++" by Lee and Mark Atkinson (Que Corporation) which presents an excellent discussion of overloaded new and delete operators. In fact there...
1
by: Douglas Peterson | last post by:
class Allocator { public: virtual void * Alloc(size_t) = 0; virtual void * Free(void*) = 0; }; class Object { public:
1
by: Swaq | last post by:
Or, at least, I find it complicated :-) Hopefully it is not that hard but here goes: I have two tables: Persons and Relations Persons contain personal data such as person_ID, name, adresse,...
8
by: paulwilliamsonremove | last post by:
Hi, Using Access 2003. I am trying to delete records from one table/query ("qryHistoryPersonIDs") if they don't exist in another table ("qryDonations"). But the SQL syntax I came up with is...
8
by: starman7 | last post by:
i have a table with objects in categories and their positions. there will be several rows with category 400, and they will have various positions, i want to delete only the row with the lowest...
9
by: ProgrammerGal | last post by:
I am hoping this is a quick easy question for someone! :) I am trying (struggling) with moving data from Sql Server to a Lotus Notes table. I am using SQL Server 2000, I have a Lotus Notes...
15
by: LuB | last post by:
I am constantly creating and destroying a singular object used within a class I wrote. To save a bit of time, I am considering using 'placement new'. I guess we could also debate this decision -...
4
nomad
by: nomad | last post by:
Hello Everyone: I'm working on a project for a client in which they want to add and delete events for a selected day on a calendar. I have built the calendar and added the events, but I'm having...
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
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.