aspose file tools*
The moose likes JDBC and the fly likes query disaster Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "query disaster" Watch "query disaster" New topic
Author

query disaster

fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
i have a table with these are not unique.
so, i have multiple rows of such as shown below:


I hope you got the idea of the data in the table.
I want to fetch all the rows from this table with unique
so the fetch should display data something like this


Can you give me a query for this kind of result fetching?
thanks in advance
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

Two possible solutions:orRegards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
i little mistake in my analysis:


i want to select unique with a good value of
good value means, C123.. kind of string in case values are 0 and C123..
0 in case all the values are 0.
Other than zero, the other string value will always be same.
Paul Campbell
Ranch Hand

Joined: Oct 06, 2007
Posts: 338
what Jan said with a where clause of summit_id = 'c123'
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
the ids were an example. I need to fetch all the rows in a similar fashion.
Emanuel Kadziela
Ranch Hand

Joined: Mar 24, 2005
Posts: 186
You might be able to get what you want this way:

select tyche_id,max(summit_id) from "your table" group by tyche_id.

the group by will get you uniqueness of the tyche_ids and the aggregate function will get you some meaningful value for the summit_id, unless it's 0 in which case it will return the 0. It's a bit of a kludge, but it might work. Otherwise, you will have to use a combination of join, group by and case statements to craft the result set more precisely to your needs.
fahad siddiqui
Ranch Hand

Joined: Jun 14, 2006
Posts: 85
will work? the type of the column is varchar and the data is also varchar.

the case statement does work. thanks.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2516
    
  10

You will get the alphabetic maximum, not the numerical one.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: query disaster