Home > PL/SQL, Snippets > (PLSQL) How to get MAX(num)+DISTINCT str

(PLSQL) How to get MAX(num)+DISTINCT str

Tuesday, 18 August, 2009 Leave a comment Go to comments

CLEAR;  
with t as  
 (
 select '11' num, 'string1' str, '1' DATA from dual union all  
 select '12' num, 'string1' str, '3' DATA from dual union all  
 select '15' num, 'string1' str, '3' DATA from dual union all  
 select '25' num, 'string2' str, '10' DATA from dual union all  
 select '26' num, 'string2' str, '2' DATA from dual union all  
 SELECT '29' num, 'string2' str, '4' DATA from dual  
 )  
SELECT * FROM t  
WHERE num IN (SELECT MAX(num) FROM t tt WHERE t.str = tt.str);
Advertisements
Categories: PL/SQL, Snippets Tags: ,
  1. suresh kumar patra
    Monday, 24 August, 2009 at 2:00 pm

    how many max number in employee table?

    • Monday, 24 August, 2009 at 2:18 pm

      “num” – number [unique (autoincrement)]
      “str” – varchar [similar data]
      “data” – varchar [random data]

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: