Pair problem ( SQL of the query )

Hi,
Do you know how should look an SQL query to make possible viewing pairs, but the pairs cannot repeat ?
For example in emp relation we want to get workers which works in proper department ( table dept) and view it by pairs - but the same pairs cannot repeat e.g.
JONES RESEARCH SMITH
WARD SALES ALLEN
This example result of this query. I have two relations emp and one relation dept and I don't want to get the same names but with the different order -
JONES RESEARCH SMITH
WARD SALES ALLEN
SMITH RESEARCH JONES
ALLEN SALES WARD
this last two shouldn't appear.
Thanks for answer.

If we have got system built-in tables EMP i DEPT with structure
CREATE TABLE EMP
(EMPNO NUMERIC(4) NOT NULL,
ENAME VARCHAR(10),
JOB VARCHAR(9),
MGR NUMERIC(4),
HIREDATE DATETIME,
SAL NUMERIC(7, 2),
COMM NUMERIC(7, 2),
DEPTNO NUMERIC(2))
INSERT INTO EMP VALUES
(7369, ‘SMITH’, ‘CLERK’, 7902, ‘17-DEC-1980′, 800, NULL, 20)
INSERT INTO EMP VALUES
(7499, ‘ALLEN’, ‘SALESMAN’, 7698, ‘20-FEB-1981′, 1600, 300, 30)
INSERT INTO EMP VALUES
(7521, ‘WARD’, ‘SALESMAN’, 7698, ‘22-FEB-1981′, 1250, 500, 30)
INSERT INTO EMP VALUES
(7566, ‘JONES’, ‘MANAGER’, 7839, ‘2-APR-1981′, 2975, NULL, 20)
INSERT INTO EMP VALUES
(7654, ‘MARTIN’, ‘SALESMAN’, 7698, ‘28-SEP-1981′, 1250, 1400, 30)
INSERT INTO EMP VALUES
(7698, ‘BLAKE’, ‘MANAGER’, 7839, ‘1-MAY-1981′, 2850, NULL, 30)
INSERT INTO EMP VALUES
(7782, ‘CLARK’, ‘MANAGER’, 7839, ‘9-JUN-1981′, 2450, NULL, 10)
INSERT INTO EMP VALUES
(7788, ‘SCOTT’, ‘ANALYST’, 7566, ‘09-DEC-1982′, 3000, NULL, 20)
INSERT INTO EMP VALUES
(7839, ‘KING’, ‘PRESIDENT’, NULL, ‘17-NOV-1981′, 5000, NULL, 10)
INSERT INTO EMP VALUES
(7844, ‘TURNER’, ‘SALESMAN’, 7698, ‘8-SEP-1981′, 1500, 0, 30)
INSERT INTO EMP VALUES
(7876, ‘ADAMS’, ‘CLERK’, 7788, ‘12-JAN-1983′, 1100, NULL, 20)
INSERT INTO EMP VALUES
(7900, ‘JAMES’, ‘CLERK’, 7698, ‘3-DEC-1981′, 950, NULL, 30)
INSERT INTO EMP VALUES
(7902, ‘FORD’, ‘ANALYST’, 7566, ‘3-DEC-1981′, 3000, NULL, 20)
INSERT INTO EMP VALUES
(7934, ‘MILLER’, ‘CLERK’, 7782, ‘23-JAN-1982′, 1300, NULL, 10)
CREATE TABLE DEPT
(DEPTNO NUMERIC(2),
DNAME VARCHAR(14),
LOC VARCHAR(13) )
INSERT INTO DEPT VALUES (10, ‘ACCOUNTING’, ‘NEW YORK’)
INSERT INTO DEPT VALUES (20, ‘RESEARCH’, ‘DALLAS’)
INSERT INTO DEPT VALUES (30, ‘SALES’, ‘CHICAGO’)
INSERT INTO DEPT VALUES (40, ‘OPERATIONS’, ‘BOSTON’)
And the aim is to show all workers by pairs but if I have a pair :
JONES RESEARCH SMITH
the pair in opposite direction shouldn't appear ( pair SMITH RESEARCH JONES shouldn't appera), and so on for other pairs.
Thanks for answer.

Similar Messages

  • SQL 2012 SP1 - How to determine a query that causes Error 8623 in SQL Log: The query processor ran out of internal resources and could not produce a query plan. This is a rare event...

    We are getting multiple 8623 Errors in SQL Log while running Vendor's software.
    How can you catch which Query causes the error?
    I tried to catch it using SQL Profiler Trace but it doesn't show which Query/Sp is the one causing an error. 
    I also tried to use Extended Event session to catch it, but it doesn't create any output either.
    Error:
    The query processor ran out of internal resources and could not produce a query plan. This is a rare event and only expected for extremely complex queries or queries that
    reference a very large number of tables or partitions. Please simplify the query. If you believe you have received this message in error, contact Customer Support Services for more information.
    Extended Event Session that I used;
    CREATE EVENT SESSION
        overly_complex_queries
    ON SERVER
    ADD EVENT sqlserver.error_reported
        ACTION (sqlserver.sql_text, sqlserver.tsql_stack, sqlserver.database_id, sqlserver.username)
        WHERE ([severity] = 16
    AND [error_number] = 8623)
    ADD TARGET package0.asynchronous_file_target
    (SET filename = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xel' ,
        metadatafile = 'E:\SQLServer2012\MSSQL11.MSSQLSERVER\MSSQL\Log\XE\overly_complex_queries.xem',
        max_file_size = 10,
        max_rollover_files = 5)
    WITH (MAX_DISPATCH_LATENCY = 5SECONDS)
    GO
    -- Start the session
    ALTER EVENT SESSION overly_complex_queries
        ON SERVER STATE = START
    GO
    It creates only .xel file, but not .xem
    Any help/advice is greatly appreciated

    Hi VK_DBA,
    According to your error message, about which query statement may fail with error message 8623, as other post, you can use trace flag 4102 & 4118 for overcoming this error. Another way is looking for queries with very long IN lists, a large number of
    UNIONs, or a large number of nested sub-queries. These are the most common causes of this particular error message.
    The error 8623 occurs when attempting to select records through a query with a large number of entries in the "IN" clause (> 10,000). For avoiding this error, I suggest that you could apply the latest Cumulative Updates media for SQL Server 2012 Service
    Pack 1, then simplify the query. You may try divide and conquer approach to get part of the query working (as temp table) and then add extra joins / conditions. Or You could try to run the query using the hint option (force order), option (hash join), option
    (merge join) with a plan guide.
    For more information about error 8623, you can review the following article.
    http://blogs.technet.com/b/mdegre/archive/2012/03/13/8623-the-query-processor-ran-out-of-internal-resources-and-could-not-produce-a-query-plan.aspx
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • Problem in running the query on ODS

    Hi All,
    I have been trying to run the query which consists of only 25 fields and doen't contain much calculations and routines and trying to restrict even 7000 records.
    That too result in system failure reporting on storage parameters somtimes giving dump as well.
    Could you please suggest me the solution for this as this is urgent requirement.
    Thanks
    Suryam

    Hi,
    Are you using a filter / restrictions in the query,if So create a Secondary index which can be suitable(same order) to this filterations/restrictions.
    You can find the order in where cluase in the sql statement used in the query execution.you can see it in SM50.
    With rgds,
    Anil Kumar Sharma .P

  • Problem while changing the query of the field in Oracle apps 11.5.10

    Hello All,
    Requirement:
    User want to change the query of the LOV attached to Ordered item field on Line items tab on the Sales order form in Order managment
    Block name = 'LINE'
    Field name = 'ORDERED_ITEM_DSP'
    LOV attached to this field in FMB: ITEMS
    LOV attached to this field in front end: ENABLE_LIST_LAMP
    Problem: Following code is firing at all points (Debug messages are appearing at all points) but Query of the LOV attached to item is still same.
    How can in FMB LOV is "ITEMS" and in front end "ENABLE_LIST_LAMP"
    My guess is there is some problem with the LOV name which we are passing in the code below. Because LOV name attached to item are different in front end and FMB. There is no LOV in FMB which has “SYSTEM ITEMS Description” kind of structure.
    I have written following code in custom.pll (l_chr_rg_query is query taken from the record group attached to “ITEMS” named LOV with some modifications ex: rownum<6 so that it will show only 6 records in LOV if it is really firing our query for LOV)
    IF ( form_name = ‘OEXOEORD’
    AND block_name = ‘LINE’
    AND field_name = ‘ORDERED_ITEM_DSP’
    AND event_name = ‘WHEN-NEW-ITEM-INSTANCE’
    THEN
    MESSAGE (‘message1’);
    l_chr_rg_name := ‘XXLION_UNIFORM_CODE_RG’;
    l_chr_rg_query :=
    ‘SELECT item, item_id, item_description, inventory_item_id,item_identifier_type,null           item_identifier_type_meaning, ‘
    || ‘inventory_item, address, cust_address, item_definition_level ‘
    || ‘FROM oe_return_items_v ‘
    || ‘WHERE (sold_to_org_id = :parameter.lov_num_param1 OR sold_to_org_id IS NULL)’
    || ‘ and rownum < 6 ORDER BY item’;
    MESSAGE (‘message2’);
    l_rg_id := FIND_GROUP (l_chr_rg_name);
    MESSAGE (‘message3’);
    IF ID_NULL (l_rg_id)
    THEN
    MESSAGE (‘Creating record group here’);
    l_rg_id :=
    CREATE_GROUP_FROM_QUERY (l_chr_rg_name, l_chr_rg_query);
    END IF;
    errcode := POPULATE_GROUP (l_rg_id);
    MESSAGE (‘ERROCODE is : ‘ || errcode);
    L_lov_id := FIND_LOV (‘ITEMS’); --My guess is this LOV name is the source of problem.
    MESSAGE ('Error code is4');
    SET_LOV_PROPERTY (l_lov_id, group_name, l_rg_id);
    MESSAGE ('Error code is5');
    SET_ITEM_PROPERTY ('LINE.ORDERED_ITEM_DSP', lov_name, 'ITEMS');
    END IF;

    I found that there is no problem with code. My problem is not technical, its a functional problem.
    It is related to Inventory's "System Items" KFF.
    Can anybody tell me, to this "System Items" KFF, one value set is assigned. but it is of none type of value set. so from where the values in LOV are coming?

  • Problem in executing the Query

    Hi Experts,
    I hava query on FIAR_C03, while i am executing that query it is showing one error message and immediately it is disconnecting BW server. that error message is
    Abort Characterstic 0clr_doc_no is not available in the infoprovider
    in details it is showing  0clr_doc_no has deleted from the infocube, but 
    i didn't delete anything from that infocube.
    I have executed that qury in RSRT, I got the Output.
    What happend how can i get the output and wt is the problem.
    Please help me to do this.
    Helpful answer will be appreciated with full points.
    Thanks in advance,
    Venkat

    Hi Venkat,
    If that object is not present in InfoCube, how can you add that in query based on same InfoCube?
    For that, either you have to add that object in InfoCube or delete the same object from the query definition. It seems all the queries based on the InfoCube are using the same object. Thatu2019s the reason why they are giving error.
    The syntax check (Check Query) option is available in the BEx Query Designer. It is 13th icon from the left on icon bar.
    Regards,
    Yogesh

  • Problem in Testing the Query Template

    Hi All,
      I created mysql connection in the Dataservers and connection status was successful.we created FixedQuery(Fixed Query is SQLQuery Template type) in the query template editor.when i am trying to test the sql query "select * from emp" it is not displaying any result template.But sql query is working fine we tested in MYSQL server console.
    please do the need ful
    Regards
    Srikanth M

    Hi,
    I written fixed sql query(select * from emp) in the  query tab,When i select the "Test" button one window is opening ,text/html selected  and submited "OK" button .It is not opening any result template in the browser.
    Regards
    Srikanth

  • Problem while executing the query

    Hi,
    I have a query when iam trying to execute the query it is giving following error
    Error Summary
    Exception occured while processing the current request; this exception cannot be handled by the application or framework
    If the information on this page does not help you locate and correct the cause of the problem, contact your system administrator
    To facilitate analysis of the problem, keep a copy of this error page Hint: Most Web browsers allow you to select all content, and copy and paste it into an empty document (such as in an email or simple text file)
    Root Cause
    The initial exception that caused the request to fail was:
         Select a valid Date (OR) Fiscal Period (OR) Calendar Month         
    com.sap.mw.jco.JCO$Exception: (104) RFC_ERROR_SYSTEM_FAILURE:      Select a valid Date (OR) Fiscal Period (OR) Calendar Month         
    at com.sap.mw.jco.MiddlewareJRfc.generateJCoException(MiddlewareJRfc.java:455)
    at com.sap.mw.jco.MiddlewareJRfc$Client.execute(MiddlewareJRfc.java:1452)
    at com.sap.mw.jco.JCO$Client.execute(JCO.java:3979)
    at com.sap.mw.jco.JCO$Client.execute(JCO.java:3416)
    at com.sap.ip.bi.base.application.service.rfcproxy.impl.jco640.Jco640Proxy.executeFunction(Jco640Proxy.java:267)
    Iam not sure why i could not able to execute this query.I could able to execute and run other queries.
    Please help me..
    thanks in advance

    Hi,
    Please check if you have used any formulae or function modules to derive the fiscal period/month from calday. Maybe the date being assigned is not of the same format as expected due to which the error (input valid date or calmonth or fiscal period) is being generated.
    Regards,
    Manoj

  • Strange problem while executing the Query.......

    Hi,
    I have created a new query and I am facing the strange behaviour.
    When I execute it , it works fine but when one of my colleague execute it , it does not return any value for one of the Price variable.
    It works fine with most of the people I have checked except one.
    Can somebody let me know the reason.....?
    Thanks , Jeetu

    Hello,
    If it is authorization problem go to transaction st01 and mark the first check for authorization. Under filter insert the user. Click Trace On.
    Execute the query with that user and just after the lack of authorization message click trace off.
    Read the trace.
    Do the same with your user and compare the log of the two.
    You'll see what is missing.
    Assign points if helpful.
    Diogo.

  • Problem while saving the query

    I have created transport request from solman, and when I try to save the query under the the request it is asking whether to create a new task under a different specific user, if I cancel it the query is not getting saved, please help me.
    thanks

    Hey Sudeer,
    This happens becoz the Query that u are changing is already locked by another transport request which is owned by diffrent user..
    Ask the relevant user to release the corresponding request, so that u dont get the prompt again....
    To avoid it, just create a new Query( totally new query ) and then assign your transport request to it..
    Reward points for usefull answer...
    Regards,
    Anand Rangarajan

  • Problem in Changing the Query of LOV using Forms Personalisation

    Hi all,
    I have a problem while trying to change the LOV of job field in the people--> assignment form. I am trying to do through forms personalisation. I defined all the rquired fields:
    Following are the description of fields Idescribed in the form Personalisation:
    Trigger Event: WHEN-NEW-FORM-INSTANCE
    in actions tab:
    10-- Built In--Create Record Group With Query
    11-Property----LOV
    Target Object--JOBS
    Property Name--GROUP_NAME
    vALUE--jobs(rECORD gROUP NAME created above)
    It is validated successfully,
    but when trying to open the form it is giving an error 'cannot create record group jobs'..
    Can anybody help me with this..
    Thanks and Regards
    Raj

    I found that there is no problem with code. My problem is not technical, its a functional problem.
    It is related to Inventory's "System Items" KFF.
    Can anybody tell me, to this "System Items" KFF, one value set is assigned. but it is of none type of value set. so from where the values in LOV are coming?

  • Problem to Design the Query

    Hi all,
    User have a requirement of Dashboard like ,
    Profit Center Hierarchy wise Actual Sale , Plan Sales & PY Actual Sales
    And they Want Graph Like
    Fiscal Year Period Wise Value of Actual Sales of Every Profit Center Group .
    And then they want Fiscal Year Period Wise , signle trend line for Plan Sales & single trend line for PY total Actual Sales
    I am Able to Get Result till Current Year Actual Sales & Plan Sales.
    But i am not able to get trend line for PY ( Previous Years) Actual Sales.
    My Query Stucture is llike :
    In Rows : Profit Center Grouping with Actual & Plan Sales
    In Columns : Fiscal Year Period.
    I am not able to Get FiscalYear Period Wise Previous Years Actual Sales .
    Pls Help.
    Thanks

    Hi Satish,
    I pass in
    in_staff_id = 'D237738'
    in_month = 4
    in_group_id =-1,
    in_team_id = -1,
    in_colour = 0 -- red or 1 or 2 or 3
    the result for red is 7
    for yellow = 4
    for green is 12
    and for black is 0
    The result is not right. The red is calculated properly yellow should only be 3 and green only be 6.
    I hope this helps,
    Thanks again,
    Chris

  • Problem in putting the query condition for negative stocks.............

    Hi,
    I am applying condition to display negative stocks.
    Situation is like In the columns , I have key figure stock quantity and stock status(QI , blocked etc)
    Accordning to the stock status column is created and all the materials are displayed for that status.
    I have put condition on stock quantity to display only the negative stocks.
    The result of the report is ok but in one case it is displaying stock qnty 1(positive stock) as well as the negative qnty for that material for different QI status.
    I am not able to understant why this positive value is getting displayed in the report when I have put the condition , stock < 0 .
    It is happening for only one material whose batch number is same and storage location is also same. But positive value is surpirsing me.
    Please let me know if somebody has solution or idea how to solve this situation.
    Thanks,
    Jeetu

    Please dont repost. it saves time for everyone

  • Problem in writing the query

    hi
    I want to write aquery as
    l_query1 varchar2(1000)
    default 'select COLUMN_NAME ,DATA_TYPE from all_tab_columns where rownum <=2';--where TABLE_NAME = || ||p_tname;
    p_tname has the value for TABLE_NAME .
    for this I need to include the value of p_tname in single quotes.
    i want the output as
    'select COLUMN_NAME ,DATA_TYPE from all_tab_columns where rownum <=2';--where TABLE_NAME = 'oracle' ';
    how to do so?
    thanks
    cheers

    e.g.
    l_query1 := 'select column_name from all_tab_columns where table_name = '''||p_tname||'''';

  • Problem during the setting the query data source name in forms 6i

    We are now doing assignments in forms 6i actually there is a problem during setting the query data source name in run time.
    The problem is
    declare
    v_query varchar2(200),
    begin
    v_query :='(select empno,ename,deptno from emp where hiredate =' || control .value1 ||')';
    go_block('emp');
    set_block_property('emp',query_data_source_name,v_query);
    end;
    that bolded area is the problem that ia varchar value the single qoutes embedded with that value.how can i embedded single qoutes in that concatenation.
    That is now query will run like select empno,ename,deptno from emp where hiredate =control.value
    But we need like select empno,ename,deptno from emp where hiredate ='control.value'
    Message was edited by:
    Punithavel

    Thanks for your response
    We fixed the error
    and the answer is
    declare
    v_query varchar2(200),
    begin
    v_query :='(select empno,ename,deptno from emp where hiredate = ' ' ' || control .value1 ||' ' ' ) ' ;
    go_block('emp');
    set_block_property('emp',query_data_source_name,v_query);
    end;

  • How to define the query condition of Image Theme in MapBuilder?

    Hi,
    I'm trying to add an dynamic Image Theme in OracleMap, but there's a problem.I defined the query condition of Image Theme like this:
    select scanimage,shap from image where scanimgid=467
    The shap column is the MBR column
    And the XML CODE:
    <?xml version="1.0" standalone="yes"?>
    <styling_rules theme_type="image" image_column="SCANIMAGE" image_format="JPEG" image_unit="M" image_resolution="1.0">
    <rule>
    <features> select scanimage,shap from image where scanimgid=467 </features>
    </rule>
    </styling_rules>
    When i preview this Image Theme ,there is an ORA-00936 error means lack of expression.
    Is there any problem with my definition?Or can query an image from an Image Theme?
    Thanks a lot for your help!
    Message was edited by:
    N.Mars
    null

    Hi Mars,
    predefined image theme definition does not support a "select" statement in the <features> tag. You should just define a query condition in the <features> tag.
    It seems that you are trying to use an image theme in Oracle Maps, but it currently does not support a FOI image theme. You should add a predefined image theme as part of the basemap, and maybe add scales values to set the visibility range of this image theme.
    Joao

Maybe you are looking for