SELECT DISTINCT with another table I want to use distinct to display my data.
But I don't know how to do it.This is my code.I want to display table gtest_version field max(poly_version)

select distinct on (rule_name) 
rule_name,rule_version,polyname,state 
from rule 
order by rule_name,rule_version DESC
If I understand your requirements correctly, you want to join the other table on polyname and then get the max() of poly_version, like

SELECT rule_name, rule_version, polyname, state, max(poly_version)
  FROM rule r JOIN gtest_version g ON r.polyname = g.polyname
 GROUP BY rule_name, rule_version, polyname, state
 ORDER BY rule_name, rule_version DESC;


However, your query and description does not tell how you want to pick the right row from the rule table.  My query will return all of these, while your DISTINCT ON will not...