Win a copy of Kubernetes in Action this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

SQL Query related  RSS feed

 
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'
 
Rancher
Posts: 42972
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.
 
author & internet detective
Marshal
Posts: 37714
579
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!