File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes SQL Query related Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "SQL Query related" Watch "SQL Query related" New topic

SQL Query related

Yuvaraj Deena

Joined: Aug 24, 2013
Posts: 8

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%' )
select count(*) from customer_table where DocumentNo = '12345'
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
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

Joined: May 26, 2003
Posts: 33130

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.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: SQL Query related
jQuery in Action, 3rd edition