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

Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
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: 42371
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.

Ping & DNS - my free Android networking tools app
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 30789

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.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
subject: SQL Query related