473,386 Members | 1,745 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.

Thinking in Sets versus Procedural code

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?

Apr 11 '07 #1
2 1445
--CELKO-- wrote:
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?
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
Apr 11 '07 #2
On Apr 11, 5:56 pm, Lennart <erik.lennart.jons...@gmail.comwrote:
--CELKO-- wrote:
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?

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
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.

Apr 13 '07 #3

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

Similar topics

5
by: Oksana Yasynska | last post by:
Hi all, I'm running Postgres 7.2.1 and I need to return multiple row sets from plpgsql function. I'm new in plpgsql but according documentation and everything I could find in the mailing list...
5
by: Stanley Sinclair | last post by:
I have a need to return multiple result sets from a stored procedure. Want that SP to call others to get the data. Win2003, db2 8.1.5. Can't figure out how to handle open cursors, and return...
13
by: parley | last post by:
After several years of programming WWW applications in ASP.NET (and several other frameworks) our division has come to what might seem a counterintiutive conclusion: Writing ASP.NET code in a...
4
by: Mark Kamoski | last post by:
Hi Everyone. What is the real difference between writing a Sub versus writing a Function with no return value? It seems to me that both of these would need to compile to the same IL, so it...
13
by: blangela | last post by:
I have decided (see earlier post) to paste my Word doc here so that it will be simpler for people to provide feedback (by directly inserting their comments in the post). I will post it in 3 parts...
4
by: Mohitz | last post by:
Any pointers as to how one should go about porting procedural type code into object oriented code?? --- Mohit
17
by: chsalvia | last post by:
I would say that, in general, you don't need to learn C before learning C++. In fact, I would go as far as saying that there's really no reason to learn C at all. Most programming tasks are...
2
by: justnjose | last post by:
what is the difference between object oriented Per and procedural perl
20
by: Mr.SpOOn | last post by:
Hi, I need a structure to represent a set of integers. I also need to perform on this set some basic set operations, such as adding or removing elements, joining with other sets and checking for...
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...

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.