oracle - SQL selection query that discards rows that share some value with another row -


suppose have next sql table, these sample values:

id    date        user     publish ---------------------------------- 1     05/20/16    peter    1 2     05/20/16    peter    2      <= discarded 3     05/20/16    john     2 4     05/28/16    john     1 5     05/28/16    john     2      <= discarded 6     07/01/16    peter    2 7     07/01/16    john     2 

what want query select rows in case there 2 rows same date , user, retrieve 1 'publish' value '1', in example rows 1, 3, 4, 6 , 7.

i resolve problem programmatically wonder if exists way solve proper sql query.

any appreciated.

this discard first row (ordered publish) each group of date , user:

select id, "date", user, publish   (   select t.*,          row_number() on ( partition "date", user order publish ) rn     table_name t ) rn = 1; 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

unity3d - Fatal error- Monodevelop-Unity failed to start -