473,395 Members | 2,437 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,395 software developers and data experts.

DB2 equivalent to this Sybase syntax

I'm just getting my feet wet in DB2 UDB (9.x), after years as a Sybase
DBA. In Sybase, if I wanted to delete data from one table based on
joining that table to a second table, I'd use this syntax

delete TABLE_A
from TABLE_A T1,
TABLE_B T2
where T1. col-a = T2.col-a and
T1.col-b = T2.col-b

What's the equivalent syntax in DB2?

Thanks.
Sep 22 '08 #1
5 2911
Hi!

Look at the merge statement:

MERGE INTO Table_A A
USING Table_B B
ON A.col1 = B.col1
AND A.col2 = B.col2
WHEN MATCHED THEN
DELETE;

/dg

"Richard" <rm*******@gmail.comwrote in message news:d2**********************************@m45g2000 hsb.googlegroups.com...
I'm just getting my feet wet in DB2 UDB (9.x), after years as a Sybase
DBA. In Sybase, if I wanted to delete data from one table based on
joining that table to a second table, I'd use this syntax

delete TABLE_A
from TABLE_A T1,
TABLE_B T2
where T1. col-a = T2.col-a and
T1.col-b = T2.col-b

What's the equivalent syntax in DB2?

Thanks.

Sep 22 '08 #2
Thanks, that worked. :-)

I incorrectly guessed that I could use the same logic to delete rows
where
there's NO matching record. Here's what I tried (bad syntax):

merge into Table_A T1
USING Table_B T2
on T1.col_a = T2.col_a
when not matched then delete;

What I'm trying to achieve now is: delete the parent record if there
are no remaining children.

Thanks again.

Sep 22 '08 #3
Richard wrote:
Thanks, that worked. :-)

I incorrectly guessed that I could use the same logic to delete rows
where
there's NO matching record. Here's what I tried (bad syntax):

merge into Table_A T1
USING Table_B T2
on T1.col_a = T2.col_a
when not matched then delete;

What I'm trying to achieve now is: delete the parent record if there
are no remaining children.

Thanks again.
DELETE FROM T WHERE NOT EXISTS(SELECT 1 FROM T AS CHILD WHERE T.pk =
child.fk)

That will wipe one level. Now if you want this to cascade things are
getting interesting....

Cheers
Serge
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Sep 22 '08 #4
Thanks.

I had justed tried the Sybase syntax, which worked. I'm assuming it
equivalent to
what Serge wrote. Here's what I used:

delete from Table_A T1
where not exists (select 1 from Table_B T2 where
T2.col_a = T1.col_a);
Sep 22 '08 #5
Richard wrote:
Thanks.

I had justed tried the Sybase syntax, which worked. I'm assuming it
equivalent to
what Serge wrote. Here's what I used:

delete from Table_A T1
where not exists (select 1 from Table_B T2 where
T2.col_a = T1.col_a);
Yes that's ANSI SQL.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab
Sep 23 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: Robert Brown | last post by:
suppose I have the following table: CREATE TABLE (int level, color varchar, length int, width int, height int) It has the following rows 1, "RED", 8, 10, 12 2, NULL, NULL, NULL, 20...
14
by: php newbie | last post by:
I am getting error messages when I try to delete from a table using the values in the table itself. The intent is to delete all rows from TableA where col_2 matches any of the col_1 values. ...
2
by: eight02645999 | last post by:
hi i am writing a CGI to process some database transactions using the Sybase module. so in my CGI script, i have: .... import Sybase import cgitb; cgitb.enable(display=1 ,...
2
by: pankaj_wolfhunter | last post by:
Greetings, In sybase there is a create default statement in order to create a default object. like CREATE DEFAULT one as 1 go this object then can be bound to different table columns as...
2
by: pankaj_wolfhunter | last post by:
Greetings, In Sybase global variable @@transtate keeps track of the current state of a transaction. Sybase server determines what state to return by keeping track of any transaction changes...
3
by: Alex Murphy | last post by:
As title, Thanks
4
by: tamarindm | last post by:
I am using the following to connect to a Sybase server. OleDbConnection Conn= new OleDbConnection(); string connstr = "Provider=Sybase ASE OLE DB Provider;Data Source=SERVER;User...
1
by: sunitapd | last post by:
Plz if ne1 knows how to convert rows into columns ie to use Pivot tell me.I m using the DBArtisan tool for accessing the Sybase server.
0
by: =?ISO-8859-1?Q?S=E9bastien_Sabl=E9?= | last post by:
WHAT IS IT: The Sybase module provides a Python interface to the Sybase relational database system. It supports all of the Python Database API, version 2.0 with extensions. The module is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.