Two Laptop Bag*
The moose likes JDBC and the fly likes SQL SELECT DISTINCT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "SQL SELECT DISTINCT" Watch "SQL SELECT DISTINCT" New topic
Author

SQL SELECT DISTINCT

Adam Shirley
Greenhorn

Joined: Jan 31, 2008
Posts: 1
I have a servlet that accesses a datafile, performs a query, and retrieves the information from it. Here is what the select string currently looks like:

SELECT tdydno, tdload, tltype, tlacctno, taname, tlcymd, tlamount, tdstatus, tdsrn

I want to perform a SELECT DISTINCT on tdload. That is, I do not want the same load number displayed twice. It's okay if everything else is displayed twice, just not tdload. Using the keyword DISTINCT here automatically tries to apply it to all of the other words, I think. Is there a way around this?
Srikanth Basa
Ranch Hand

Joined: Jun 06, 2005
Posts: 241
I believe you are looking for Group By ?
Kevin Smither
Ranch Hand

Joined: Oct 22, 2007
Posts: 30
Yes, you can use GROUP BY but in this case you have to supply aggregate functions for the other columns
 
Consider Paul's rocket mass heater.
 
subject: SQL SELECT DISTINCT
 
Similar Threads
Tell me this Logic
Complicated SQL query help
Query Question
insert unique name into the table
Display the sequence numbers on the output rows of a select in Oracle 10g