• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

query disaster

 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two possible solutions:orRegards, Jan
 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what Jan said with a where clause of summit_id = 'c123'
 
fahad siddiqui
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the ids were an example. I need to fetch all the rows in a similar fashion.
 
Emanuel Kadziela
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will work? the type of the column is varchar and the data is also varchar.

the case statement does work. thanks.
 
Jan Cumps
Bartender
Posts: 2599
12
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get the alphabetic maximum, not the numerical one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic