Contractor UK Bulletin Board  PayStream

Go Back   Contractor UK Bulletin Board > Contractor UK Forums > Technical
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 23rd August 2007, 14:47   #21
richard-af
Fingers like lightning
 
richard-af's Avatar
 
Join Date: Jul 2007
Location: Monaco-on-Thames
Posts: 956
Default

Quote:
Originally Posted by King Cnvt View Post
Couldn't you just ring up all the customers and ask them if they have any orders? FFS, kids of today....
Generous of spirit and magnanimous in defeat. I salute you, sir.

SQL, eh? It can be tricky, can't it?
richard-af is offline   Reply With Quote
Old 23rd August 2007, 19:53   #22
TheFaQQer
Lord of the FAQ
 
TheFaQQer's Avatar
 
Join Date: Oct 2006
Location: North West
Posts: 6,480
Default

If only Milan were around to help you guys out, now that he's a DBA.

I think I would do it with a "where not exists" clause, but haven't looked at the plan for it.
__________________
Test please delete - The greatest thread in CUK history (TM)

Visit TPDVille - the online TPD City
TheFaQQer is offline   Reply With Quote
Old 23rd August 2007, 20:16   #23
Gonzo
Contractor Among Contractors
 
Gonzo's Avatar
 
Join Date: Sep 2006
Location: London
Posts: 1,490
Default

I am not a coder but I have come across the phenomenon that some versions of some databases will do a tablescan when you are not expecting it, so you are earning your money by knowing when that will happen.

I would vote for the subquery option because it is the one that I would write, but I can accept that in the real world that could trigger a tablescan when it shouldn't. The foreign key should be indexed in both tables otherwise the DBA should be shot.

IMO

EDIT - even if all the fields are indexed that is not always enough to stop a tablescan.

Last edited by Gonzo : 23rd August 2007 at 20:58.
Gonzo is online now   Reply With Quote
Old 24th August 2007, 08:28   #24
richard-af
Fingers like lightning
 
richard-af's Avatar
 
Join Date: Jul 2007
Location: Monaco-on-Thames
Posts: 956
Default

Quote:
Originally Posted by Gonzo View Post
I am not a coder but I have come across the phenomenon that some versions of some databases will do a tablescan when you are not expecting it, so you are earning your money by knowing when that will happen.

I would vote for the subquery option because it is the one that I would write, but I can accept that in the real world that could trigger a tablescan when it shouldn't. The foreign key should be indexed in both tables otherwise the DBA should be shot.

IMO

EDIT - even if all the fields are indexed that is not always enough to stop a tablescan.
What ARE you on about? Full Table Scans, Fast Full Scans, etc. are not associated, in particular, with either Joins or Subqueries. The CBO decides HOW it will gather the data. The only way to be sure is to run it and see. Then tweaks-tests-tweaks-tests, etc. Then you know. No need to go through it all again, unless the stats become significantly out-of-step with reality, or an index is added, a table is partitioned, etc., etc.


Incidentally, a Full Table Scan can be the right thing to do.

There are books on all this, as well as bizillions of lovely web sites.

That old copy of "Oracle 7: Ye Goode Guyde To The Magicks and Mysteryes" is a bit redundant.

Last edited by richard-af : 24th August 2007 at 08:34.
richard-af is offline   Reply With Quote
Old 24th August 2007, 09:14   #25
DimPrawn
Godlike
 
DimPrawn's Avatar
 
Join Date: Jul 2005
Posts: 10,101
Default

A left join usually sorts it all out.
__________________
By the time you finish reading this sentence, the national debt will have risen by another £1,500 - which you or your children will have to repay.

Just so you know.
DimPrawn is offline   Reply With Quote
Old 24th August 2007, 09:18   #26
richard-af
Fingers like lightning
 
richard-af's Avatar
 
Join Date: Jul 2007
Location: Monaco-on-Thames
Posts: 956
Default

Quote:
Originally Posted by DimPrawn View Post
A left join usually sorts it all out.
Aaaagggghhhh!!!!! Sob! <clinking of gin bottle against glass>
richard-af is offline   Reply With Quote
Old 24th August 2007, 09:19   #27
ElectricChair
Banned
 
ElectricChair's Avatar
 
Join Date: Aug 2007
Location: The Planet wibble
Posts: 183
Default

Quote:
Originally Posted by DimPrawn View Post
A left join usually sorts it all out.
whats wrong with a right join?
ElectricChair is offline   Reply With Quote
Old 24th August 2007, 09:32   #28
richard-af
Fingers like lightning
 
richard-af's Avatar
 
Join Date: Jul 2007
Location: Monaco-on-Thames
Posts: 956
Default

Numpties.
richard-af is offline   Reply With Quote
Old 24th August 2007, 10:43   #29
xoggoth
Super poster
 
xoggoth's Avatar
 
Join Date: Jul 2005
Location: xoggoth towers
Posts: 2,959
Default

Customers, orders. Dull. If I ever designed a new language I would only sell it with a condition "Not to be used in boring commercial apps"
__________________
bloggoth
xoggoth is offline   Reply With Quote
Old 24th August 2007, 13:59   #30
gables
Lurker not a fighter
 
gables's Avatar
 
Join Date: Jul 2006
Posts: 77
Default

Quote:
Originally Posted by Ruprect View Post
I have 2 tables, e.g. customers and orders. Foreign key between is customerID. I want to know which customers have zero orders.

What SQL will achieve this?

Thanks
On a more philosophical note can you have a customer with zero orders?
gables is offline   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 Off
HTML code is Off
Forum Jump


All times are GMT. The time now is 21:19.


Advertisers
PayStream

CUK Navigation

Contractor Alliance
Formed a new Ltd Co?

20% off business insurance
£10 off Bauer & Cottrell contract reviews
Find co-workers & client introductions

Increase your value to clients here

Fast Company Formation
Same day online company formation £75 + VAT

Form your Ltd Co Here

Contractor Services


 
Content Relevant URLs by vBSEO 2.4.0 © 2005, Crawlability, Inc.