• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • 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

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    #21
    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?

    Comment


      #22
      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.
      Best Forum Advisor 2014
      Work in the public sector? You can read my FAQ here
      Click here to get 15% off your first year's IPSE membership

      Comment


        #23
        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; 23 August 2007, 20:58.

        Comment


          #24
          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; 24 August 2007, 08:34.

          Comment


            #25
            A left join usually sorts it all out.

            Comment


              #26
              Originally posted by DimPrawn View Post
              A left join usually sorts it all out.
              Aaaagggghhhh!!!!! Sob! <clinking of gin bottle against glass>

              Comment


                #27
                Originally posted by DimPrawn View Post
                A left join usually sorts it all out.
                whats wrong with a right join?

                Comment


                  #28
                  Numpties.

                  Comment


                    #29
                    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

                    If everything isn't black and white, I say, 'Why the hell not?'
                    John Wayne (My guru, not to be confused with my beloved prophet Jeremy Clarkson)

                    Comment


                      #30
                      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?

                      Comment

                      Working...
                      X