File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

SQL Query related

Yuvaraj Deena
Greenhorn

Joined: Aug 24, 2013
Posts: 8
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
Marshal

Joined: Mar 22, 2005
Posts: 42371
    
  64
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
Marshal

Joined: May 26, 2003
Posts: 30789
    
157


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