Reputation: 67
Im using postgress pgadmin as my database. In my application I need to search details from a specific table.
For that I used method like below.
SELECT DISTINCT xx , yy
FROM (
SELECT xx , yy
) total
Here I used DISTINCT to remove duplicate entries. But when I use that, it will sort the filtered data according to tableID.
So is there any method to remove duplicates & filetere data without sorting them according to tableID ?
Upvotes: 0
Views: 75
Reputation:
If you do not specify any order the rows will generally be returned in the order that they were inserted into the table, but this is not garanteed.
You can specify the order with ORDER BY
as you need
ORDER BY xx, yy
or the opposite with ORDER BY yy, zz
ORDER BY xx DESC
will return the row with the largest value of xx
first.ORDER BY x / y
SELECT DISTINCT xx , yy
FROM (
SELECT xx , yy
) total
ORDER BY xx , yy;
Upvotes: 1