• Post Reply Bookmark Topic Watch Topic
  • New Topic

SQL Query related

 
Yuvaraj Deena
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i'm beginner in SQL queries, When i trying to get particular records count from customer table(database), i used these queries(see below). Since, both has return the same results (display record count). What is difference between them? Which statement could be better?

select count (*) from customer_table where upper( DocumentNo ) like upper( '%12345%' )
(or)
select count(*) from customer_table where DocumentNo = '12345'
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not a question of which statement is better - they do different things. "upper" and "like" are standard SQL features that I'm certain are explained in any SQL manual.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36007
422
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

contains unnecessary code. 12345 are numbers, not uppercase characters

Which means the first query should be:


Whether this revised query or the = query is better depends on your dataset. If you know 12345 is the actual value, = is better than like because it is more specific.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!