Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
i got some data in database:

Name | Country | Status

Mary | USA | Pending

Jane | Japan | Pending

Jane | Korea | Pending

Adrian | China | Pending

Peter | Singapore | Pending

Jack | Malaysia | Pending

Adrian | China | Updated

Jane | Japan | Updated

May i know how to use the SELECT query to select all the data with no duplicate data in hsqldb? (If the duplicates data exist, select only the Status with Updated)
Posted
Comments
[no name] 18-Jun-13 20:47pm    
Have you tried using DISTINCT?
Sean Wee 18-Jun-13 20:57pm    
I try use this:

SELECT Name, Country, MAX(Status) as Status FROM (
SELECT TOP 100 PERCENT *
FROM NameCountry
ORDER BY Name ASC, Country ASC, Status DESC
) G
GROUP BY G.Name, G.Country
ORDER BY G.Name, G.Country

and it only work for sql but not hsqldb.

1 solution

You can use select distinct to get each value only once.

select distinct name, country from table where status = 'updated' However, if you did a select distinct on all three columns, you'd get the pairs, pending and updated. I think you need to do what I just said, and then join that to a select that gets pending values that are not in this list. Really, your table design is broken. If the names are the same person, why do they have more than one status ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900