Query required to compress multiple records

I have a table containing customer name and module as follows
Customer        Module_id         Company_Name
AAA                   9                       ABC
AAA                  13                      ABC
AAA                  21                      ABC
AAA                    5                      ABC
BB                     6                       XYZ
BB                     7                       XYZ
BB                     21                     XYZ
CCC                  13                      EFG
CCC                    6                      EFG
CCC                    7                     EFG
DD                     13                     UVW
DD                       9                    UVWI want to retrieve customer and company name which have
module id as 9 or 13 but NOT 21
The criteria I used is module_id in (9,13) and module_id <> 21
However the output is:
CCC EFG
DD UVW
DD UVW
The output I want is:
CCC EFG,
DD UVW (Only once)
Can any body provide the query?

Sounds like you need to put DISTINCT in your select or use a group by.
I.e
select distinct customer, company
from your tables
where your table join
module_id in (9,13) and module_id <> 21
or
select customer, company
from your tables
where your table join
module_id in (9,13) and module_id <> 21
group by customer, company

Similar Messages

  • Update multiple records using checkbox

    Hi All,
    I have one requirement related to multiple record update using checkbox.
    HTML form has 6 columns and many rows.
    Now i want to update all 6 columns in the table for selected checkbox.
    Can any body give me some idea/code about this.
    Thanks in advance.
    Ravi

    I did not understand your idea.
    multiple columns can be updated as follows...
    update table set col1=value,col2=value,col3=value where conditions;
    We are using adodb driver in our environment. So I will explain concern to it. Store all the form new values in $var array and you can pass this $var to query execution.
    A vague idea
    $rs = $conn->Execute($update_sql,$var);     
    if ($rs===false) die('DB Error: '. $conn->ErrorMsg() );

  • Locking multiple records in a database table at a time

    Hi Experts,
       I have a requirement to lock multiple records in the database table for writing. I have created lock object in SE11. But with this we have only 2 possibilities either lock entire table or lock a single record at a time.
       My requirement is, i have table with key field PROJECTID. I want more than one project to be locked, but not the complete table. I dont have any other field in the table to compare.
    Thanks in advance..
    Regards,
    Asrar

    Hi ,
    Try with FOR UPDATE in the SELECT sentence.
    SELECT FOR UPDATE *
        INTO Internal_Table
      FROM Table
    WHERE Conditions.
    UPDATE "Table_name" FROM TABLE  Internal_Table.
    COMMIT WORK.
    This sentence blocks only the records that satisfy of the WHERE conditions (not the entire table) and unlocks after commit work.
    Hope this information is help to you.
    Regards,
    José

  • JDev 11g: Create Multiple Record.

    Hi,
    I have a requirement to create multiple record by clicking the create button multiple times and on one click it should save all the records. Everything is working fine, but the issue is,
    when user created 4 records and the 5th record he doesn't want to create then issue is comming. Application is forcing him to enter the data, is there is any way to handle this situation.
    I mean, if the 5th record doesn't contain any data.. it should save 4 records only. Please suggest me the solution to achieve this.
    Thanks,
    Rajesh

    Hi Shay,
    Thanks for your reply. But your second solution will never occur in my case because validator methods will not allow user to click on save button without entering the proper data.
    Is there any otherway instead of deleting the record to achieve this functionality.
    Thanks,
    Rajesh

  • Generate Query in PLSQL to return Well Formed XML with Multiple records

    Hi there
    This is very urgent. I am trying to create a PLSQL query that should retrieve all records from oracle database table "tbl_Emp" in a well formed xml format. The format is given below
    *<Employees xmlns="http://App.Schemas.Employees" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">*
    *<Employee>*
    *<First_Name></First_Name>*
    *<Last_Name></Last_Name>*
    *</Employee>*
    *<Employee>*
    *<First_Name></First_Name>*
    *<Last_Name></Last_Name>*
    *</Employee>*
    *</Employees>*
    To retrieve data in above format, I have been trying to create a query for long time as below
    SELECT XMLElement("Employees",
    XMLAttributes('http://App.Schemas.Employees' AS "xmlns",
    *'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi"),*
    XMLElement("Employee", XMLForest(First_Name, Last_Name)))
    AS "RESULT"
    FROM tbl_Emp;
    But it does not give me the required output. It creates <Employees> tag with each individual record which I don't need. I need <Employees> tag to be the root tag and <Employee> tag to repeat and wrap each individual record. Please help me in this as this is very urgent. Thanks.

    Hi,
    Please remember that nothing is "urgent" here, and repeating that it is will likely produce the opposite effect.
    If you need a quick answer, provide all necessary details in the first place :
    - db version
    - test case with sample data and DDL
    That being said, this one's easy, you have to aggregate using XMLAgg :
    SELECT XMLElement("Employees"
           , XMLAttributes(
               'http://App.Schemas.Employees' AS "xmlns"
             , 'http://www.w3.org/2001/XMLSchema-instance' AS "xmlns:xsi"
           , XMLAgg(
               XMLElement("Employee"
               , XMLForest(
                   e.first_name as "First_Name"
                 , e.last_name  as "Last_Name"
           ) AS "RESULT"
    FROM hr.employees e
    ;

  • How to insert multiple records in a single query

    Dear all,
    Can you please tell
    how to insert multiple records in a single query ??

    INSERT INTO table_name (column_1, column_2) VALUES ('value_A', 'value_B')OR
    INSERT INTO table_name
    (column_1, column_2)
    SELECT 'value_A', 'value_B' FROM DUAL
    UNION ALL
    SELECT 'value_C', 'value_D' FROM DUAL
    ;Edited by: Benton on Nov 9, 2010 1:59 PM

  • SQL Query - Multiple records from value of field

    I have a table that has the following lay out
    ID
    AreaUnitServes
    Filter1Quantity
    Filter1Size
    Filter2Quantity
    Filter2Size
    And I’m trying to convert it to
    FkPSAUnitsID
    Size
    Location
    I’ve got the following query started but I’m stuck on how to INSERT INTO multiple records by the value of Filter1Quantity. I also have to query for Filter2Quantity.
    INSERT
    INTO RapidServ.dbo.PSAFilters
    (FkPSAUnitsID,Size,Location)
    SELECT ID
    AS FkPSAUnitsID,Filter1Size
    AS Size,
    AreaUnitServes
    AS Location
    FROM RapidServ.dbo.PSA
    Thanks,
    why767

    Please follow basic Netiquette and post the DDL we need to answer this. Follow industry and ANSI/ISO standards in your data. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data. We need
    to know the data types, keys and constraints on the table. Avoid dialect in favor of ANSI/ISO Standard SQL. And you probably need to read and download the PDF for: 
    https://www.simple-talk.com/books/sql-books/119-sql-code-smells/
    >> I have a table that has the following lay out <<
    How nice for you! Why did you draw ASCII pictures?  It has all kinds of magical names. The table is nameless because it is forbidden by a wizard to speak its name? There are generic, universal “size” and “location”of nothing in particular. Is the “fk-”
    prefix a meta data design error for “foreign key”? We never do that in RDBMS; name a data element for what it is by its nature, not for how it was used in one place in one schema. This is why we have no magical “id” in a valid schema. Data elements do not
    change names from table to table. 
    You seem to have inherited a pile of garbage with a repeated group in it. Look up First Normal Form (1NF). You also do not know why row is not a record and why fields are  not columns. Did you notice that “area_unit_serves” is a sentence and not
    a name? 
    >> I’ve got the following query started but I’m stuck on how to INSERT INTO multiple records [sic] by the value of Filter1Quantity. I also have to query for Filter2Quantity. <<
    My guess until I get a usable business rules and DDL is that you can use a UNION something like this skeleton: 
    INSERT INTO PSA_Filters (psa_units_id, filter_size, area_service_unit)
    SELECT psa_units_id, filter_1_size, area_service_unit
      FROM Magic_Nameless_Stuff
    UNION ALL
    SELECT psa_units_id, filter_2_size, area_service_unit
      FROM Magic_Nameless_Stuff;
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • SAP Query using internal table because of multiple records in KONV

    Hi
    Im using abap code to write to an internal table, how do you get the internal table fields to show in query report.
    Reason I have added abap code is I have a query for purchase order tables EKKO and EKPO. I would like to show any conditions attached to these purchase orders using EKKO-KNUMV = to KONV-KNUMV.
    Prolem is KONV can have multiple records. So added code to write records from KONV to a internal table. Problem is how do I get the internal table files to show in query report. Have added fields as additional fields and included them in the field group.   
    In info sturcture I have defined internal table in code 'DATA'  included  the select in 'Record procesing'
    Any help will be appreciated. Thanks

    Yes, and the problem is that sometimes that item has two of the same conditions.  One that SAP enters automatically and one that the end  user enters.  I want to understand how this is happening so that I can fix it.

  • Adhoc Query Requirement with Multiple Data Source

    Hi All,
    I have a Adhoc Query Requirement with Multiple Data Source. Is there any way to achive it. Other than Resultant set and bring into Model.
    Thanks
    SS

    You can compare stuff in the EL, but I don't think this is what you need.
    You can just use Java code in the backing bean class for all the business logic. You can use DAO classes for database access logic. Finally for displaying you can use the JSF tags such as h:outputText.

  • Opening multiple-record form in query mode

    Hi,
    I have two problems:
    1. I have a portlet form based on a table that I would like to open in query mode. I've tried this code:
    - in the "..before displaying the form" block :
    WWV_MASTER_GENSYS_4 (
    p_block_name => p_block_name ,
    p_object_name => p_object_name,
    p_instance => p_instance ,
    p_event_type => p_event_type ,
    p_user_args => p_user_args ,
    p_session => p_session );
    It brings back the first record successfully. But when I press the 'next' button, I get this error 'An unexpected error occurred:ORA-06502:PL/SQL:numeric or value error:NULL index table key value (WWV-16016)
    2. I would like to display this form as a multiple records form. But it will only display one record at a time. Has anyone been able to do this?
    I would appreciate any assistance in advance.
    Thu

    Maybe this will help you:
    http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a85397/operator.htm#1029184

  • Query is returning multiple records for a bank account id and party id

    Hi All,
    I am not getting why this query is returning multiple records for a particular bank account id and party id:
    SELECT instrument_payment_use_id
    ,instrument_type
    ,instrument_id
    ,start_date
    ,ext_pmt_party_id
    FROM iby_pmt_instr_uses_all
    WHERE instrument_id =:lv_num_ext_bank_account_id
    and exists (select 1 from iby_external_payees_all b where PAYEE_PARTY_ID= :lv_num_party_id and b.ext_payee_id = ext_pmt_party_id)
    I want above values to be used in api iby_disbursement_setup_pub.set_payee_instr_assignment in R12.
    Please help asap.
    Thanks

    O/P of query run for
    SELECT rowid, instrument_payment_use_id
    FROM iby_pmt_instr_uses_all
    WHERE instrument_id =6642
    AND EXISTS (
    SELECT 1
    FROM iby_external_payees_all b
    WHERE payee_party_id= 85470
    AND b.ext_payee_id = ext_pmt_party_id);
    is below:
    Rowid     INSTRUMENT_PAYMENT_USE_ID
    AABiDXAGIAABhiKAAS     236586
    AABiDXAGRAABSjtAAz     148437
    The version is R12

  • Multiple record insert query

    I realise that this is probably a simple question and I'm just looking for some general pointers. I've already looked through these forums and on the web so don't all jump down my throat at once!
    If I want to insert multiple records into a Mysql database/table, can I do it through Dreamweaver Insert Record function and using a repeat region, or can multiple inserts only be done through programming the PHP/Mysql side of things?
    I need to insert a row for each player in a football match, and need to input starting 11, subs, man of the match etc with checkboxes, so have binded the checkboxes to the table and would like to use a repeat region if this is poss? Or will I have to insert a separate row of checkboxes for each player?
    Any advice much appreciated
    Cheers all
    Bez

    I figured out the method to insert record with auto increment primary key. I listed the code block below:
    char m_SeqNamePositions[32] = "MyPositions";
    DbSequence *m_pSeqPositions;
    m_pDBPositions = new Db(NULL, 0);
              m_pDBPositions->open(NULL, pszFileName, szFileName, DB_BTREE, DB_CREATE, 0);          // 无数据文件
              m_pSeqPositions = new DbSequence(m_pDBPositions, 0);
              Dbt key((void *)m_SeqNamePositions, (u_int32_t)strlen(m_SeqNamePositions));
              m_pSeqPositions->open(NULL, &key, DB_CREATE);
    db_seq_t SeqNum;
         m_pSeqPositions->get(0, 1, &SeqNum, 0);
         Dbt key((void *)&SeqNum, (u_int32_t)sizeof(SeqNum));
         Dbt data(pRecord, sizeof(*pRecord));
         return m_pDBPositions->put(NULL, &key, &data, DB_NOOVERWRITE);
    m_pSeqPositions->close(0);
              m_pDBPositions->close(0);
    delete m_pSeqPositions;
    delete m_pDBPositions;
              m_pDBPositions = NULL;

  • Multiple records in query..

    Hi,
    select * from service_request sr, service_request_det srd,service_user su
    where
    sr.srid = srd.srid
    and srd.empid = su.empid
    service_user --> this table has record of same employeeid multiple times
    srd --> this table have employee id multiple times but that employee id cannot be outside of service_user table.
    Now, when i join "and srd.empid = su.empid" i get multiple records so can it be possible to retrieve single record eventough i join using above condition or any other way to achieve this..
    Thanks,
    JP                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    I have no idea why there are multiple empids in your service_user table, but there must be some other columns in that table you can use to narrow down the ones you want. Maybe an Active flag, a termination date, something. Otherwise, you'll have no idea which one to join to and which of the rows you want in your result set.

  • How to handle multiple records in BPMN process

    Hi All,
    We are using Oracle BPM 11g.In my requirement,I am using the database adapter to get the data from table and I need to validate the each record and update the status of that record from the BPM Process.But I dont know how to handle if multiple records come at a time.Can anybody please helpout from this problem.
    Thanks in advanced.
    Narasimha Rao.

    Can you have a look at this post: http://redstack.wordpress.com/2010/09/30/iteratingtraversing-arrays-in-bpm/
    It's solving a different problem, but the key is that it's using a multi-instance subprocess to iterate over an array of "things" that need to be acted in. In your case it's the set of results from the db query rather than the set of tests in the example. But the principle is the same. You'd take collection of rows from the DB and process them in a multi-instance subprocess. The text that begins with the following would be good place to start:
    "Now let’s implement the body of our process. We will use the Subprocess object to handle the traversal of the array of tests. Drag a Subprocess from the component palette on the right into the process and drop it on the line between the Start and End nodes."
    In the loop characteristics you'd define whether you want to execute serially or in parallel.

  • How to query berkeley db with multiple keys

    Hi all,
    Is there a way to query a berkeleydb using multiple keys. For example, I want to query a order record with orderID and orderDirection, orderID is a string and orderDirection is a char.
    Is there a way to do so?
    Regards,
    -Bruce

    Hi Bruce,
    Yes, you would use the same approach with a join cursor.
    Here is a simple example, simplified for brevity. Suppose the primary database "books" stores information about books, and that these books could have multiple authors. Following is some example data and the structure of these databases:
    books.db (primary db -- ISBN is primary key)
    isbn_1 | {author_1, author_2; ...}
    isbn_2 | {author_2; ...}
    isbn_3 | {author_1, author_3; ...}
    booksAuthors.db (secondary db -- author is the secondary key, the secondary key extractor generates multiple keys)
    author_1 | isbn_1
    author_1 | isbn_3
    author_2 | isbn_1
    author_2 | isbn_2
    author_3 | isbn_3
    To get the books authored by author_1 and author_2 for example, you would do the following:
    - position a cursor in the booksAuthors.db secondary db, using DBcursor->get() with the DB_SET flag, on the records whose key (secondary key) is author_1;
    The cursor will be positioned on the duplicates list for author_1:
    author_1 | isbn_1
    author_1 | isbn_3
    - position a cursor in the booksAuthors.db secondary db, using DBcursor->get() with the DB_SET flag, on the records whose key (secondary key) is author_2, hence duplicates list for author_2:
    author_2 | isbn_1
    author_2 | isbn_2
    - create a join cursor using DB->join, using the previous two cursors.
    An excerpt from the above documentation page explains the way a join cursor works:
    "Joined values are retrieved by doing a sequential iteration over the first cursor in the curslist parameter, and a nested iteration over each secondary cursor in the order they are specified in the curslist parameter. This requires database traversals to search for the current datum in all the cursors after the first."
    Hence, the data item (primary key from the primary db) that results is isbn_1.
    Regards,
    Andrei

Maybe you are looking for

  • Saved PDF does not  restore data properly when reopened

    I have a simple PDF I created in Livecycle Designer where I fill in some input fields and save the PDF. The problem I am having is when I save the PDF, and then reopen it, the data in the input fields are no longer where I originally typed them in. T

  • Question for SQL execution plan, strange..

    HI, all We meet a strange problem for a execution plan. First, we have a StoreProc, it runs around less than 20 secs. One day, it runs more than 5 mins (Execution plan 1). I checked all the index (fragmentation is low and Scan density is high), and r

  • SQL for AR Aging 7 Buckets Report

    Hi, I am currently working on producing a query to produce the same results as the Aging 7 Buckets report in the AR module of Oracle Enterprise Suite. I have take the code from the Oracle report and produced my query but it is slightly out. Has anyon

  • Subscription not renewed by the desired date

    I have a monthly subscription which was supposed to be renewed today i.e. Aug 13, 2011. Payment for the same was already done 10days back and the same is reflected in purchase history. However, the minutes haven't been added yet. How do I get this re

  • How can I open tabs from my mobile device on my desktop?

    Hi there! Currently I'm having a desktop(Win7 x64), Mobile phone (Galaxy S2) and a tablet (Galaxy Note 10.1) Both of which run Android 4.0.4. (Also, neither is rooted) All three are running Firefox and I'm quite happy with the overall performance. Th