Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. mysql, query performance question

mysql, query performance question

Scheduled Pinned Locked Moved Database
databasemysqlperformancequestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mark_me
    wrote on last edited by
    #1

    If one has to select about 30-100 different rows from a table based on their ids... which one is best approach: 1. select * from table where id1=3 or id1=9 or id1=200 or id1=205 ... or 2. using a loop... eg foreach(string id in ids) { stmt="select * from table where id3="+id } thankyou for guidance...

    A M R 3 Replies Last reply
    0
    • M mark_me

      If one has to select about 30-100 different rows from a table based on their ids... which one is best approach: 1. select * from table where id1=3 or id1=9 or id1=200 or id1=205 ... or 2. using a loop... eg foreach(string id in ids) { stmt="select * from table where id3="+id } thankyou for guidance...

      A Offline
      A Offline
      Adam Maras
      wrote on last edited by
      #2

      Generally speaking, the fewest trips between the database client and the server, the better the application will perform. This is especially true for queries that return small amounts of data. For this reason, option #1 is more likely to perform better.

      Adam Maras | Software Developer Microsoft Certified Professional Developer

      M 1 Reply Last reply
      0
      • M mark_me

        If one has to select about 30-100 different rows from a table based on their ids... which one is best approach: 1. select * from table where id1=3 or id1=9 or id1=200 or id1=205 ... or 2. using a loop... eg foreach(string id in ids) { stmt="select * from table where id3="+id } thankyou for guidance...

        M Offline
        M Offline
        Mycroft Holmes
        wrote on last edited by
        #3

        Does MySql not have an IN operation, I hate using OR in a where clause.

        Select * from Table where ID in(1,23,4,56,700)

        Never underestimate the power of human stupidity RAH

        M 1 Reply Last reply
        0
        • M mark_me

          If one has to select about 30-100 different rows from a table based on their ids... which one is best approach: 1. select * from table where id1=3 or id1=9 or id1=200 or id1=205 ... or 2. using a loop... eg foreach(string id in ids) { stmt="select * from table where id3="+id } thankyou for guidance...

          R Offline
          R Offline
          Robin_Roy
          wrote on last edited by
          #4

          Based on the 2 options that you gave, the first option is better.

          1 Reply Last reply
          0
          • A Adam Maras

            Generally speaking, the fewest trips between the database client and the server, the better the application will perform. This is especially true for queries that return small amounts of data. For this reason, option #1 is more likely to perform better.

            Adam Maras | Software Developer Microsoft Certified Professional Developer

            M Offline
            M Offline
            mark_me
            wrote on last edited by
            #5

            thankyou

            1 Reply Last reply
            0
            • M Mycroft Holmes

              Does MySql not have an IN operation, I hate using OR in a where clause.

              Select * from Table where ID in(1,23,4,56,700)

              Never underestimate the power of human stupidity RAH

              M Offline
              M Offline
              mark_me
              wrote on last edited by
              #6

              thankyou all

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups