• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

SQL Help please

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.
 
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.:tantrum:
 
Last edited: 21:16
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.:tantrum:

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: 09:28
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"
 
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?:rolleyes:
 

Advertisers

Back
Top