A quick SQL question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bad B0y
    Confirmed User
    • Aug 2002
    • 160

    #1

    A quick SQL question

    Say for example you have 10 000 products in a table and they all fall into 30 categories.

    Now you want to select 50 products from a couple of those categories (could be any amount between 1-30 of those categories pending on how many the user wants).

    Do you,
    A: make one select query to get all 10 000 products and filter the results yourself.
    or
    B: make one select query per category(meaning 1-30 queries) and limit each query to 50.

    Which would be more efficient?
  • Machete_
    WINNING!
    • Oct 2002
    • 14579

    #2
    If on train going 40 mph. gets a 30 min headstart, when will the train going 55 catch up?

    Comment

    • Alky
      Confirmed User
      • Apr 2002
      • 5651

      #3
      B as long as your query is efficient.

      Comment

      • grumpy
        Too lazy to set a custom title
        • Jan 2002
        • 9870

        #4
        B and i dont thinks you wanna show 1000 products at the same time... 20 cats times 50 products .....so B
        Don't let greediness blur your vision | You gotta let some shit slide
        icq - 441-456-888

        Comment

        • AcidMax
          Confirmed User
          • May 2002
          • 1827

          #5
          OR depending on your skill level you use joins and such and if your tables are setup right you might be able to pull all the information you need in a single query with GROUP BY and other similar SQL functions. Do reasearch about the DB type and understand when and when not to use database normalization.

          All really depends on the layout and what you are trying to get specifically from it.

          Andy
          Latest MMA news. http://www.mmawrapup.com

          Comment

          • Bad B0y
            Confirmed User
            • Aug 2002
            • 160

            #6
            yeah. think i'll write both functions and run 'em up against each other.

            and yes i do have to much time on hand I need a new project after the succesful launch of http://webmasters.za.net

            Comment

            • Bad B0y
              Confirmed User
              • Aug 2002
              • 160

              #7
              ok. you have all the products along with all the category id's in one table. so you want to select 50 products per categoryid, but it's not that easy.

              Comment

              • Penrod
                Confirmed User
                • Aug 2001
                • 3580

                #8
                Originally posted by ebus_dk
                If on train going 40 mph. gets a 30 min headstart, when will the train going 55 catch up?
                not long

                Comment

                • Rory
                  Confirmed User
                  • Jul 2002
                  • 616

                  #9
                  You seem to keep asking questions and its a bit uncclear exactly what you want. However keep in mind one thing ..... let sql do the work as opposed to PHP,Perl, etc. Dont pull out all the data , then sort - you want to sort , etc. then pass the relevant data into your program. You will always get better results if you do the sorting, etc. within sql. If you cant create a query for it, you will need to go back and redesign your db (write it down first , dont create as you go). If you wing it you will run into issues down the road , be they performance, normalization, etc.

                  Rory

                  Promote a site that actually retains members!

                  Comment

                  • Bad B0y
                    Confirmed User
                    • Aug 2002
                    • 160

                    #10
                    thanks allot guys.

                    i was a bit unsure about 20 queries or one hughe one.

                    Comment

                    Working...