Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
Database Servers
DB2InformixIngresMS SQLOraclePervasive.SQLPostgreSQLProgressSybase
Desktop Databases
FileMakerFoxProMS AccessParadox
General
General DB TopicsDatabase Theory
Related Topics
Java Development.NET DevelopmentVB DevelopmentMore Topics ...

Database Forum / DB2 Topics / April 2007

Tip: Looking for answers? Try searching our database.

Thinking in Sets versus Procedural code

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
--CELKO-- - 11 Apr 2007 20:43 GMT
I am trying to collect a few examples of SQL queries that were done
with a "procedural mindset" and another solution done with a "set-
oriented mindset".  I have a short article at
http://www.dbazine.com/ofinterest/oi-articles/celko5
with an example of what I want.

Anyone got some examples?
Lennart - 11 Apr 2007 23:56 GMT
> I am trying to collect a few examples of SQL queries that were done
> with a "procedural mindset" and another solution done with a "set-
[quoted text clipped - 3 lines]
>
> Anyone got some examples?

Not really, just curious whats wrong with an exists query?

select distinct x.col1, x.col2, x.col3, x.col4
from foobar x
where not exists (
    select 1 from foobar y
    where (x.col1, x.col2, x.col3)
        = (y.col1, y.col2, y.col3)
     and coalesce(y.col4,1) <> 0
)

It seems more straight forward

/Lennart
--CELKO-- - 13 Apr 2007 23:17 GMT
> > I am trying to collect a few examples of SQL queries that were done
> > with a "procedural mindset" and another solution done with a "set-
[quoted text clipped - 16 lines]
>
> It seems more straight forward

I like that one, but a lot of SQLs do not have the row constructor and
comparisons.  The other advantage of using aggregate functions is that
some products keep MIN(), MAX(), COUNT(), etc. as part of their
statistics so you just look them up and do not have to compute them.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.