• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sql

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Help please.
I have just two values Yes/No.

What is faster approach?
SELECT * FROM table WHERE smoker = 'No'
or
SELECT * FROM table WHERE smoker LIKE 'N%'
Thank you.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using an Oracle database, then you can test it yourself very easily (in SQL*Plus). Just time both queries by issuing the command:

before running the queries.
[Or am I missing something?]
Hope this helps you.
Good Luck,
Avi.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manuel Paco:
Help please.
I have just two values Yes/No.

What is faster approach?
SELECT * FROM table WHERE smoker = 'No'
or
SELECT * FROM table WHERE smoker LIKE 'N%'
Thank you.

 
unni krishnan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Manuel Paco:
Help please.
I have just two values Yes/No.

What is faster approach?
SELECT * FROM table WHERE smoker = 'No'
or
SELECT * FROM table WHERE smoker LIKE 'N%'
Thank you.



the secound one is the faster access
thank you
 
Avi Abrami
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unni,
I'd really appreciate it if you would show how you arrived at your conclusion.
Thankyou,
Avi.
 
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In general, the LIKE operator will be an order of magnitude slower than an = operator. Also, a LIKE operator will not be able to take advantage of any indexes which may exist on the operand columns.
However, your sample is so simple, you might not be able to find a difference. For example, if you time the two queries in Oracle, I bet the second one (whichever one is run second) will run fastest. That's because the server will have cached all the results from the first query, then the second query only needs to retrieve from the server cache.
 
reply
    Bookmark Topic Watch Topic
  • New Topic