Query to get the records with same last name

I need to write a single sql query to get all records with duplicate last_name's. For example, if tab1 has 4 records:
10     Amit     Kumar
20     Kishore          Kumar
30     Sachin     Gupta
40     Peter     Gabriel
then the query should return
10     Amit     Kumar
20     Kishore     Kumar
id, name,L_name being the 3 columns in table
Apprecite you help.
Thank you
Mary

SQL> create table mytable (id,name,l_name)
  2  as
  3  select 10, 'Amit', 'Kumar' from dual union all
  4  select 20, 'Kishore', 'Kumar' from dual union all
  5  select 30, 'Sachin', 'Gupta' from dual union all
  6  select 40, 'Peter', 'Gabriel' from dual
  7  /
Table created.
SQL> select id
  2       , name
  3       , l_name
  4    from ( select t.*
  5                , count(*) over (partition by l_name) cnt
  6             from mytable t
  7         )
  8   where cnt > 1
  9  /
                                    ID NAME    L_NAME
                                    10 Amit    Kumar
                                    20 Kishore Kumar
2 rows selected.Regards,
Rob.

Similar Messages

  • Query to get the record with latest date

    I have
    ACCOUNT_TABLE
    account_number
    account_event
    event_date
    ACCOUNT_TABLE
    1,Open,12 Jan 2006
    1,Open,13 Jan 2006
    1,Open,14 Jan 2006
    1,Open,15 Jan 2006
    1,Open,16 Jan 2006
    How can I get the latest record(16 Jan 2006) in one sql statement.
    Thx
    m

    if you have more account_event's then...
    SQL> with t as
      2   (select 1 account_number,'Open' account_event,'12 Jan 2006' event_date from dual union all
      3   select 1,'Open','13 Jan 2006' from dual union all
      4   select 1,'Open','14 Jan 2006' from dual union all
      5   select 1,'Open','15 Jan 2006' from dual union all
      6   select 1,'Open','16 Jan 2006' from dual union all
      7   select 1,'Close','17 Jan 2006' from dual union all
      8   select 1,'Close','18 Jan 2006' from dual union all
      9   select 2,'Open','19 Jan 2006' from dual)
    10   select * from t a
    11   where (a.account_number, account_event,a.event_date) in
    12   ((select b.account_number, account_event,max(b.event_date) from t b group by b.account_number,account_event))
    13  order by account_number;
    ACCOUNT_NUMBER ACCOU EVENT_DATE
                 1 Close 18 Jan 2006
                 1 Open  16 Jan 2006
                 2 Open  19 Jan 2006

  • Query on getting the Pane with all the items for creating Views

    Hi Group,
    I have a query as under:
    I was trying to create a sample Web Dynpro ( for ABAP ) using tcode SE80 and while creating view, I have to get the Pane with the items ( eg., Radio element, text fields, text areas, etc., kind of all UI Elements )....
    But, I was not able to get while defining the View for the Web Dynpro application....
    Please let me know if any setting has to be done to get this or any other clue as to get this Pane...
    Thanks in advance.
    Regards,
    Vishnu.

    hi vishnu....
            make sure you have given the host and port in the local host file in c:/.
    [link|help.sap.com/saphelp_erp2005/helpdata/en/43/e86de5008b4d9ae10000000a155369/content.htm ].
    ---regards,
       alex b justin

  • 2.0 firmware causes some contacts with same last name to not be displayed

    After upgrading to 2.0 it appears that only the first contact for a given last name is shown in contacts. Interestingly, if i search for that last name all of the contacts show up, so they are indeed syncing to the phone but are not able to be viewed in the regular contact list. I tried restoring the phone (imported settings from last sync after restore) and still have the same problem. Anyone else see the same thing?

    I'm not aware of anyone called just "John"! Everybody I know has at least a first name and a last name... therefore that is the data I enter into Address Book and iSync works fine for me and all my Sony Ericsson phones.
    If you don't provide the required data, you can't really expect iSync to work correctly.
    There is a reason for this... its because most phones don't split First and Last Name into two fields like Address Book does. So, if you have a contact named just "John" with no last name, when you sync, how does iSync know whether "John" is a First or Last name?
    To get around this iSync adds a '-' into the blank field, so that when syncing back it knows where to put the data.
    The solution is extremely simple, just provide Address Book with a first and last name (which AFAIK everyone has).

  • How to get two fields with same tech name in LIS Extractors?

    Hi Experts,
    I need "ERDAT" field from two structures (QMSM & QMFE) in 2LIS_18_IOTASK extractor.
    In LBWE first I moved ERDAT from QMSM. When I moved ERDAT from QMFE it gives an error:
    "Field with same technical name is already available in the Extract Structure".
    I don't want to create Append Structure as we need to write User exit.
    Can any one tell me how to get this field added in the extractor from QMSM and QMFE?
    Thanks for your help.
    Regards,
    Sree

    this is not possible as the all those fields are put in one structure. per definition you can't put the same field name twice in a structure, table in the data dictionary...
    hence, you really need to use an append and fill via user exit
    M.

  • Adding users to PAB group with same last name as existing

    Cannot add user to PAB group when user has same last name as an existing Group member.
    Seems to work, see number tick up and green bar flash, but, never really adds.

    Joea,
    It appears that in the past few days you have not received a response to your
    posting. That concerns us, and has triggered this automated reply.
    Has your problem been resolved? If not, you might try one of the following options:
    - Visit http://support.novell.com and search the knowledgebase and/or check all
    the other self support options and support programs available.
    - You could also try posting your message again. Make sure it is posted in the
    correct newsgroup. (http://forums.novell.com)
    Be sure to read the forum FAQ about what to expect in the way of responses:
    http://forums.novell.com/faq.php
    If this is a reply to a duplicate posting, please ignore and accept our apologies
    and rest assured we will issue a stern reprimand to our posting bot.
    Good luck!
    Your Novell Product Support Forums Team
    http://forums.novell.com/

  • How to write a query to get the total as a last row

    Hi,
    I need to get something like this ....
    |TEAM LEADER| TEAM | OCT TRN | EMPS| YTD% |
    |_____________|__________|__________|______|_______|
    | JOHN | JD Team | 12 | 12 | 100 |
    |_____________|__________|__________|______|_______|
    | Total |      | 12 | 12 | 100 |
    |_____________|__________|__________|______|_______|
    I have to get the last row as total adding the number columns ...
    Thanks in advance ...

    Take a look at the GROUP BY ROLLUP feature:
    create table t1
    (team_name      varchar2(30)
    ,wins           number
    ,losses         number
    insert into t1 values ('Hornets',3,1);
    insert into t1 values ('Panthers',4,0);
    insert into t1 values ('Wolves',2,2);
    insert into t1 values ('Badgers',0,4);
    insert into t1 values ('Hornets',1,3);
    commit;
    select decode(team_name,
                 NULL,'TOTAL',
                 team_name) team_name, sum(wins), sum(losses)
    from   t1
    group by rollup(team_name);
    TEAM_NAME                                 SUM(WINS)          SUM(LOSSES)
    Badgers                                           0                    4
    Hornets                                           4                    4
    Panthers                                          4                    0
    Wolves                                            2                    2
    TOTAL                                            10                   10

  • View the tables with same column name

    Hi all
    I have 10-20 tables and they have some same column names
    How can I know it?
    I mean, I want to know the tables which have the common column names
    Thanks...

    SQL> break on column_name
    SQL> set linesize 1000
    SQL> set pagesize 10000
    SQL> select column_name, owner, table_name
      2  from (select owner, table_name, column_name, count(*) over (partition by column_name) ct
      3        from dba_tab_columns)
      4  where ct>1
    SQL> /
    COLUMN_NAME                    OWNER                          TABLE_NAME
    AADSAS_ID_NBR                  H89UCBAC                       PS_SAD_ADA_CD
                                   H89UCBAC                       PS_SAD_ADA_SUS
                                   H89UCBAC                       PS_SAD_ADA_TMP
    AA_CODE                        H89UCBAC                       PS_RQ_CONDIN_SLVW
                                   H89UCBAC                       PS_RQ_CONDIN_SRCH
                                   H89UCBAC                       PS_DUMMYDESCR_LANG
                                   H89UCBAC                       PS_DUMMY_DESCR
                                   H89UCBAC                       PS_RQ_NOTINCOND_LV
                                   H89UCBAC                       PS_RQ_NOTINCOND_SR
    [...]Nicolas.

  • Getting Multiple Records with Same Key throws Access Violation

    Are there any known issues with PInvoke Signatures for GET .. Im gettign consistently AVL's when attempting to read Multiple Values under single key ..
    Error doesn't happens while debugging in VS 2007 , Tried turning off optimizations with no luck ..
    Im using VS 2010 and .NET 4.0 ( WIN XP) . I do have a repro. ( Im using latest bits from Oracle site as of 9/10/2010 )
    Unhandled Exception: System.AccessViolationException: Attempted to read or write
    protected memory. This is often an indication that other memory is corrupt.
    at BerkeleyDB.Internal.libdb_csharpPINVOKE.db_strerror(Int32 jarg1)
    at BerkeleyDB.DatabaseException..ctor(Int32 err) in C:\Users\gmf\db\db-5.0.26
    \csharp\DatabaseException.cs:line 78
    at BerkeleyDB.DatabaseException.ThrowException(Int32 err) in C:\Users\gmf\db\
    db-5.0.26\csharp\DatabaseException.cs:line 34
    at BerkeleyDB.Internal.DB.get(DB_TXN txn, DatabaseEntry key, DatabaseEntry da
    ta, UInt32 flags) in C:\Users\gmf\db\db-5.0.26\csharp\Internal\DB.cs:line 187
    at BerkeleyDB.BaseDatabase.Get(DatabaseEntry key, DatabaseEntry data, Transac
    tion txn, LockingInfo info, UInt32 flags) in C:\Users\gmf\db\db-5.0.26\csharp\Ba
    seDatabase.cs:line 900
    at BerkeleyDB.Database.GetMultiple(DatabaseEntry key, Int32 BufferSize, Trans
    action txn, LockingInfo info) in C:\Users\gmf\db\db-5.0.26\csharp\Database.cs:li
    ne 494
    at helloworld.Program.Main(String[] args) in C:\bdm\helloworld\helloworld\Pro
    gram.cs:line 53
    Appreciate any help.
    Thanks
    Nirmal
    Edited by: user8050299 on Sep 10, 2010 3:29 PM
    Updated with OS

    seems like oracle .NET bindings doesnt work for new CLR . It works fine with .NET 2.0
    May be Oracle folks will release new version for 4.0

  • When we click on the copy botton record with same name should not be saved

    Hi,
    Copy button will copy the record with the same name and will save it.our requirement is when we click on the copy botton ,record with same name should not be saved
    we are performing this task in custom object 12 and exposed Opportunity Name in the layout.
    Records with same Opportunity Name should not save ..when we copy the record
    Can we perform any field validation on Opportunity Name field?
    Please help
    please email me @ [email protected]
    Thanks
    Srinivas Merugu

    Opportunities that are assoicated to the same account cannot have the same name. You cannot make this unique for your whole instance. The only way that you could do this would be to create a webservice application that checks this before you save the record.
    What about defaulting the name each time this could make the record unique?

  • Get the record count from a query

    Hi,
    does anyone know how to get the record count from a sql query?
    e.g: I've got a ResultSet from the Statement.excuteQuery(), and I want to know how many records this ResultSet contains, how to get this?
    I'd read thoughout the documents of Statement and ResultSet, but couldn't find a solution, do I have to use another seperate query such as "select count(*)" to do this?
    thanks.
    Yang Liu

    If you are not using a scrollable result set then the following is the best way to do it.
    there are several key words in SQL that can be used, the one you are interested in is count();
    so if your query at the moment is
    "select col1, col2, col3 from my_table where col2=? and col3=?"you can work out how many rows will be returned by executing this command first
    "select count(col1) from my_table where col2=? and col3=?"this will return a result set with one row and one column, you can get the row count as follows:
    ResultSet rs = ps.executeQuery();
    int rowCount = rs.getInt(1);I hope this helps :)

  • Can I un-merge contacts so people with the same last name have separate entries?

    Since upgrading to iOS7 on my iPhone 4, I find that a lot of contacts were merged into single entries.  The merged contacts are people with the same address and may have same last name, but they have other contact info that differs, especially different mobile phone numbers.  Is there a way to separate such contacts so I can tell whose mobile phone number is whose?  I sync my iphone contacts with the address book on my iMac (OS 10.7.5), where each person remains a separate entry.  It is useless for me to see one entry per family on my phone when I cannot tell whose phone number is whose.  Any way to fix this?

    Select the unified contact you want to unlink
    Tap edit
    Scroll to the bottom
    Tap the red circle
    Tap the read unlink button to confirm.

  • How to get the table with no. of records after filter in webdynpro

    Dear Gurus,
    How to get the table with no. of records after filter in webdynpro?
    Thanks in advance.
    Sankar

    Hello Sankar,
    Please explain your requirement clearly so that we can help you easily.
    To get the table records from your context node use method get_static_attributes_table()
    data lo_nd_mynode       type ref to if_wd_context_node. 
    data lt_atrributes_table  type wd_this->elements_mynode. 
    lo_nd_mynode = wd_context->get_child_node( name = wd_this->wdctx_mynode ). 
    lo_nd_mynode->get_static_attributes_table( importing table = lt_atrributes_table ). 
    Note: You should have already defined your context node as a Dictionary Structure.
    BR,
    RAM

  • We get many report with same computer in the SCEP alerts.

    Hi,
    We get many report with same computer in the SCEP alerts.
    I have an email sent to support desk for "Malware detection", but same computer ends upp severaltimes long time after it have been cleand with success. I dont have "repeated malware detection" alerts enable.
    So why same alerts reported several times even if it have been removed?
    /SaiTech

    Hi,
    Please refer to the link below:
    How to Configure Alerts for Endpoint Protection in Configuration Manager
    http://technet.microsoft.com/en-us/library/hh508782.aspx
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • New info record with same details as archive one.

    Hi Experts,
    Due to some issue we want to archieve some standard info record which are created on vendor / material group / plant  basis.My query is does system allows to create new info record with same vendor / material group / plant combination after archiving earlier record which is on same basis.
    Thnaks & Regards
    Vinay

    Hi Jurgen,
    Thanks for reply.
    Our issue is while creating work order(IW31) having external services upon entering info record number in some cases in same client rate is picked up from info record condition but some times from last purchase order based on info update.
    We have checked following points.
    1.In all the cases work order type  is same.
    2.Info record are of standard type with same condition.info record are for vendor & material group combination.
    3.Checked after changing rate in info record and in purchase order but similar issue exists
    4.Compare vendor master also.
    5.Their are no contract /sch.agreement for vendors.
    Our requirement is to have rate from info record in all the cases in work order.So have two options.
    1.Archiving info record-But will need setting in SPRO and also need to create same record again with same combination.Also as their are recent purchase order against those info record not sure whether system will allow or not.Can you please tell what are prerequiste for archiving info record.
    or
    2.To remove only purchase order number updated in EINE table in those info record where this issue is occuring.We have checked in development system and after removing purchase order number in EINE table it picks up rate from info record.
    So thought of checking before removing order ref.from EINE table.
    Thanks
    Vinay

Maybe you are looking for

  • My Bluetooth simply dissapeared

    I have new , two month old iMac 21, 2013 OS X 10.8.4 Can someone help me... my bluetooth simply dissapeared... as soon as I look for it I get a message it's not awalable at the moment... Cannot use my bluetooth mouse and keyboard, instead I'm using L

  • EIS Server hangs

    Dear All, We have Hyperion 9.3V EIS running on windows. A schedule job runs every hour which 1. Builds and loads data into an ASO cube 2. Only builds a BSO cube. The problem here is that the EIS server hangs during the BSO outline build (after loadin

  • Inbound Web Service calls get error "Reliable Messaging(RM) configured, but no Message ID..."

    We are setting up the Communication System and Communication Arrangement "Business Partner Replication from SAP ERP". For protocol, we are using Type 5 - WebServices.  See screenshot below. Our error is that when we send webservice calls to our C4C,

  • Cost Center based Release Strategy for PR's

    System :4.6c At this time, we have PR release strategy with classification configured for over all release. Created a new characteristic for cost center , assigned the values for the cost center characteristic, with zeros at the beiginnig. Now when I

  • HAL Error Log Error Code = 1033 Native Code = 1030201

    Hello, I am geting the following error message in HAL logs: 05/19/2010|193212|PlanApp/Plan2|Error|Calculate|Error Code = 1033 Native Code = 1030201 Error Msg = [Wed May 19 19:32:12 2010]PRODVIS/PlanApp/Plan2/admin/Error(1030201) Cannot create object: