Unix Technical Forum

Delete with a multi-column join?

This is a discussion on Delete with a multi-column join? within the Pgsql General forums, part of the PostgreSQL category; --> Howdy! I apologize in advance for the ugly query I'm about to throw your way.... I need to delete ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 07:09 PM
leon-pg@comvision.com
 
Posts: n/a
Default Delete with a multi-column join?

Howdy! I apologize in advance for the ugly query I'm about to throw
your way....

I need to delete some data from a table based on a multi-column join.
Is there a better way to write this?

delete
from tbldata
where unitID || '_' || variableID || '_' || cycleID in
(select unitID || '_' || variableID || '_' || cycleID from
temp_data_table)

In SQL Server I would just write

delete tblData
from tblData a
inner join temp_data_table b
on a.unitID = b.unitID
and a.variableID = b.variableID
and a.cycleID = b.cycleID
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 07:09 PM
Martijn van Oosterhout
 
Posts: n/a
Default Re: Delete with a multi-column join?

On Tue, Jan 25, 2005 at 04:16:29PM -0500, leon-pg@comvision.com wrote:
> Howdy! I apologize in advance for the ugly query I'm about to throw
> your way....
>
> I need to delete some data from a table based on a multi-column join.
> Is there a better way to write this?


Either:

delete
from tbldata
where (unitID,variableID,cycleID) in
(select unitID, variableID, cycleID from temp_data_table)

Or:

delete from tblData where
tblData.unitID = temp_data_table.unitID
and tblData.variableID = temp_data_table.variableID
and tblData.cycleID = temp_data_table.cycleID

Hope this helps,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFB9sI4Y5Twig3Ge+YRAvQrAKDGjYlMFCZMWDYxhrx38h nFYuJjWgCfSriF
nhMaMDqec9HPiPkzyA3FYXA=
=5qet
-----END PGP SIGNATURE-----

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-08-2008, 07:10 PM
Tom Lane
 
Posts: n/a
Default Re: Delete with a multi-column join?

leon-pg@comvision.com writes:
> Is there a better way to write this?


> delete
> from tbldata
> where unitID || '_' || variableID || '_' || cycleID in
> (select unitID || '_' || variableID || '_' || cycleID from
> temp_data_table)


delete
from tbldata
where (unitID, variableID, cycleID) in
(select unitID, variableID, cycleID from temp_data_table)

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:53 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com