Question on "tying" two queries together

I get an error when I run the following code (shown below).
Why can't I "tie" these 2 queries together like this?
Both run fine by themselves and give me good data, I just need to tie them together.
This is for a beginning sql class, so I all I really want is an explanation as to why this is not allowed.
I'm not finding the answer in the book I have.
Any insight for a newb appreciated!
SQL> SELECT order#, isbn, title, SUM(quantity) AS SubTotal
2        FROM orderitems RIGHT OUTER JOIN books USING (isbn)
3        GROUP BY order#, isbn, title
4        ORDER BY order#
5 WHERE (isbn, title) IN
6                     (SELECT isbn, title
7                       FROM books
8                       WHERE retail - cost >
9                                        (SELECT AVG(SUM(retail - cost))
10                                         FROM books
11                                        GROUP BY isbn));
WHERE (isbn, title) IN
ERROR at line 5:
ORA-00933: SQL command not properly ended

Hi,
When the following clauses are used, they always have to be in this order:
WHERE
GROUP BY
ORDER BY
You can skip any (or all) of these, but when you use them, they have to come in that order.
Move the WHERE-clause (the whole thing, up to, but not including, the semicolon) before the GROUP BY clause.

Similar Messages

  • Tie two songs together

    I'd like to be able to tie two songs together so they always play back to back, yet in a complete shuffle mode. For instance Van Halen's Eruption / You Really Got Me Down. They appear as separate songs on the CD, so they play randomly on the shuffle. Is there a way to tie pairs of songs together?
    Thanks

    You can join tracks when importing from the CD. Insert your CD highlight the songs you want to join and choose "Join CD Tracks" from the Advanced menu and import: Adding songs from CDs to your library

  • Using Sections To Tie Two Rows Together

    I use the section capability to join two rows together.  I have a button that will duplicate the section.  Which on the screen shows perfectly.  However, when you save the file, and open it back up it does not maintain those sections.  It combines them into one.  look at this example:
    TABLE 1
    ROW 1: element1, element2               -- Row 1&2 are group as a section
    ROW 2: element1, element2
    User press the add button:
    Table 1
    ROW 1: element1, element2                -- So when the user press the add button it duplicates the section to add two more rows in order
    ROW2: element 1, element2
    ROW3: element 1, element2
    ROW4: element 1, element2
    The user now saves the form and exits...
    The user lanuches reader and opens the form. they see the follow result...
    ROW1: element1, element2
    ROW3: element1, element2
    ROW2: element1, element2
    ROW4: element1, element2
    I need the section to stay together...  Any suggestions of what can be done?
    Regards

    Uncheck the checkbox for the "Repeat Row for each Data Item" in the Bidning tab for Row2 and Row3 inside the Section.
    You are actually creating a new instance of the section (which includes Row2 and Row3). So this check box should be checked at the Section levl not at the Row level. You have already checked the Section property so remove from Row 2 and Row3.
    Thanks
    Srini

  • Integrating two queries together

    Hello expert;
    I have helped on creating a query that returned the following information below
    NAME_OR_WEEK                         TOTAL_HOURS
    Adam                                          10
    John                                          26
    Mark                                          16
    Tim                                           16
      Subtotal (06/30/2013 - 07/07/2013)          68
    Adam                                           7
      Subtotal (07/07/2013 - 07/14/2013)           7
        Grand Total                               75
    see original thread below as well
    https://forums.oracle.com/thread/2558096
    Unforunately I would like one more help to get the output in this manner with this addition
    NAME_OR_WEEK                         TOTAL_HOURS
    Adam                                          10
    John                                          26
    Mark                                          16
    Tim                                           16
      Subtotal (06/30/2013 - 07/07/2013)          68
        Needed_hours                              70
    Adam                                           7
      Subtotal (07/07/2013 - 07/14/2013)           7
        Needed_hours                              70
        Grand Total                               75
    The needed_hours is derived from a table that is defined in this manner
    create table hrs_info
    Place  varchar(1000),
    p_hrs number(30)
    insert into hrs_info values ('Group A', 70)
    There is no relationship as per say, the needed hours is just for viewing in the report. All help is appreciated. THank you

    Hi,
    user13328581 wrote:
    I suspected so but it hasn't help because it messes up the ordering and position i need and i can't get it to work. all help is appreciated
    Post your code.  I can't tell what you're doing wrong when I don't know what you're doing.
    In a UNION query, you can only ORDER BY columns that are in the result set.  Often (this case incuded) that means you have to include columns that you'd rather not see.  Your front end probably has a way to hide certain columns.  In SQL*Plus, for example, you can say
    COLUMN  week   NOPRINT
    Alternatively, you can do the UNION (including all the columns you need for sorting) in a sub-query, and then include different columns in the SELECT and ORDER BY clauses of the main query, like this:
    WITH    got_week AS
        SELECT  req_name
        ,       TRUNC (beginwork_date + 1, 'IW')       AS week
        ,       24 * (endwork_date - beginwork_date)   AS hours
        FROM    info_mech
        WHERE   beginwork_date   >= DATE '2013-07-01'
        AND     endwork_date     <  DATE '2013-08-01'
    ,    union_results AS
        SELECT    CASE 
                       WHEN  GROUPING (req_name) = 0 
                       THEN  req_name
                       WHEN  GROUPING (week) = 0
                       THEN  '  Subtotal (' || TO_CHAR (week - 1, 'MM/DD/YYYY - ')
                                            || TO_CHAR (week + 6, 'MM/DD/YYYY)')
                       ELSE  '    Grand Total'
                  END              AS name_or_week
        ,         SUM (hours)      AS total_hours
        ,   week
        ,   req_name
        ,   1     AS branch_num
        FROM      got_week
        GROUP BY  GROUPING SETS ( (week, req_name)
                                , (week)
    UNION ALL
        SELECT DISTINCT
                '  Needed_hours'  AS name_or_week
        ,       h.p_hrs     AS total_hours
        ,       w.week
        ,       NULL        AS req_name
        ,       2           AS branch_num
        FROM        hrs_info  h
        CROSS JOIN  got_week  w
    SELECT    name_or_week
    ,         total_hours
    FROM      union_results
    ORDER BY  week
    ,         branch_num
    ,         req_name

  • OBIEE: Link Two Separate Queries Together

    Hi,
    I am trying to link two separate queries together in BIEE.
    I have a query that will give me the sales value in January 2012 (monthly query)
    But I would need to use the sales value of January 2012 to help derive the weekly sales value in another query (weekly query).
    How would you link up two queries together?
    I tried using union but it doesnt seem to be working.
    Thanks.
    Bill

    Hi Billy,
    Sure, My pleasure. Here are the basic steps what you could go through.
    1. Create an analysis with your Month (January) and Sales.
    2. Save this analysis as Report1.
    3. Create another analysis with Week and Sales.
    4. Create a filter on column:Sales using the option 'Based on Another Analysis'. The analysis editor will provide you an option to browse your other analysis which you want this analysis to be based on and just click on this browse button, and navigate to and select Report1.
    5. Once you have selected Report 1 through browse option, you get down in the same pop-up the relationship and use values in column.
    So sample entries in this pop-up might look like
    Column : Sales
    Operator : is based on results of another analysis
    Saved Analysis : /My Folder/Report1
    Relationship : is equal than
    Use values in Column : Sales
    6. If you run this analysis, you could get all weekly sales figures which are equal to the january sales figures.
    Hope this helps.
    Thank you,
    Dhar

  • Working two ipads together ...

    I'm wondering what the best way would be to tie two iPads together.. the audio.. I'm wondering if they even make a iphone jack with those three ring connectors on both ends?
    any ideas?

    I would expect to find such a cable. Have you Googled for one? I would search for:
    3.5 mm male-male headphone/microphone cable
    Just curious, what are your trying to accomplish?

  • Is there a way to tie to iPads together so that when you turn a page with a tap on one, both iPads turn a page.  I am using the ipad to replace piano sheet music.  The challenge is that ordinary sheet music is on both a left and right page.

    We are trying to use an ipad to replace ordinary paper sheet music on a piano.  When truning ordinary paper pages, it is sometimes hard to grasp one page, turn it quickly and get it to stay turned.  The idea with using an ipad is that a tap turns the page, it stays turned.  However,,,,,ordinary sheet music is on both left and right pages.  With one turn you get 2 new pages.  The ipad, being smaller results in only one page and therefore twice as many page turn taps; more taps equals less hands on the piano.  If we could tie 2 ipads together and get them both to turn the page simultaneously it would be nice.  We are trying to get used to using the ipad.  We are using ForScore app to get sheet music into the ipad; we could load one with odd pages and one with even pages.  Maybe this is getting too complicated.
    Anyway to tie 2 units together
    John

    No way to control one device from the other.  But, according to ForScore, you should be able to display two sheets side by side in landscape mode (2-up view)?  Not sure if that helps as it must make the actual print smaller to do so.
    http://www.forscoreapp.com/about/#interface

  • Query works as two queries, but not as one

    I am beating my head against the wall trying to figure out why a query will not return, yet when I break it up into two queries, they both return successfully.
    There is a text index on the text_a field.
    This is my query:
    select distinct /*+ */ table_c.rec_id
    from table_d, table_n, table_c
    where ( ((create_date >='2006-03-16T00:00:00Z')
    and (misc_field='abcd')
    and (contains( text_a,'ABC or DEF or GHI or JKL or MNP') > 0 ))
    /* and (rownum <=2000) */)
    and table_c.rec_id = table_d.rec_id
    and table_c.create_date = table_d.create_date
    and table_c.rec_id = table_n.rec_id
    and table_c.create_date = table_n.create_date
    This query will not return data. I get an ora-1555 every time I let it run. The longest I let it run before getting the 1555 error was 1 hr and 50 min.
    Tests suspecting a text data problem:
    Now, here's what's puzzling. The query will run if 'JKL' is taken out. So, I thought this value may be the problem, so I ran the query with just the 'JKL' value in the "contains" clause and it did not return a value.
    Tests suspecting a date problem:
    Now, even more strange: When I ran the query (with all 5 conditions for misc_field) and looked from 2006-03-17T00:00:00Z, it returned records in less than 5 minutes. Then I queries just the 16th (create_date>='2006-03-16T00:00:00Z' and create_date < '2006-03-17T00:00:00Z' and it returned rows in less than 1 minute. So, I looked at the tokens for those dates, and there are values for all of them for each of the dates from the 16th to the present (the 21st). However, when I put them together in the query above, the query just seems to hang.
    The total number of rows that should be returned is around 650 (adding the two results that worked).
    Any suggestions? The indexes are valid, syncing is up-to-date, optimizing has no errors,a nd there are token_counts for the tokens in the $I table for the text_a field.
    This problem has crossed into a second day and the same value of the 16th (as in the query above) is still used and still does not return rows. What else should I be looking at?
    In advance, thanks for any suggestions/assistance.
    - Jenny

    I believe the 1555 error is an obscure response to (i.e. a result of) another problem.
    The create_date column is a date datatype. The NLS format matches at the session, instance and database level (nls_session_parameters, and instance, and database). The NLS_DATE_FORMAT is set to YYYY-MM-DD"T"HH24:MI:SS"Z" in each of those views. Would this still cause a potential problem?
    I neglected to say that we are on version 9.2.0.7 (both the data dictionary and the binaries).
    The response from raford suggests that the optimizer is causing the text index to be called in "functional lookup" mode. I tried testing it, forcing it to use an index. The query ran in 3.5 minutes. Then I tested the original query and received the same results. After checking with the other DBAs, one of them was updating statistics on partitions for previous days' data. The statistics were only being run on current data partitions for the current day, but apparently the method that the application uses to "update" data (which could be for previous days) is to delete it and then insert it. I am suspecting that this is the root cause of all our evil! We are currently working with the developers to get this design changed. In the meantime, I REALLY appreciate all the help/suggestions. If we see the problem occur again, we will add the hint to test and verify whether or not that is the cause. I suspect it will be. Thank you raford.
    Darn that optimizer!!!! ;-)
    Oh, just a hint: Using set autotrace traceonly explain will NOT show that each of the text index partitions is being scanned. This was what we were using for our explain plans. But, when another query, with a similar problem, was finally run, we used EM and the "Long Ops" tab to finally see that each partition was being scanned for the token, whether it needed it or not. I think I'll go back to Tom Kyte's website and look for that article on the set autotrace traceonly explain not giving a totally accurate explain plan.
    Thanks again.
    - Jenny

  • Requirement wherein I want to call two queries in parallel using ABAP Prg

    We are using RSCRM_BAPI to run a query in background and write the results to a table. We later read this table and create a file. I have a requirement u2013 wherein I want to call two queries in parallel using an ABAP program.
    For our discussion assume:
    1) Program : ZCALL_RCRMBAPI  is a program that calls RSCRM_BAPI in background and takes the query name as input
    2) Program: ZMAIN_PROGRAM  this is the main program
    The requirement is to call the ZCALL_RCRMBAPI in a loop. Also within the loop call it in parallel. Basically we have an ODS that stores ; FISCPER. So I call the two queries for a list of FISCPER.
    ZMAIN_PROGRAM - A program that reads a table (ODS ) in our case and call the two programs in a loop and both should run in parallel .
    Now if it was sequential u2013 it was easy u2013 I would just say
    Loop at L_T_FISCPER .
    Update Z_FISCPER with L_T_FISCPER-FISCPER u201C Assume Z_FISCPER is a Z table . The VARIABLE in the query Q1 and Q2 use a customer exit to read this table.
    A)       SUBMIT ZCALL_RCRMBAPI with P_QUERy = Q1 and return .
    B)      SUBMIT ZCALL_RCRMBAPI with P_QUERy = Q2 and return .
    Endloop .
    Question: How do I make these calls in parallel u2013 yet retain control in the main program?
    A)       SUBMIT ZCALL_RCRMBAPI with P_QUERy = Q1 and return .
    B)      SUBMIT ZCALL_RCRMBAPI with P_QUERy = Q2 and return .

    Instead of RSCRM BAPI you can use the RRW3_QUERY_VIEW_DATA function module for greater control over program execution...
    /people/arun.varadarajan/blog/2009/07/29/make-the-most-out-of-query-execution--part-1
    will give you pointers as to how this can be done...

  • 0PA_C01  different results from two queries on the same cube ....

    HI
    Can you please help with this  problems ...
    i am running a two queries with the same restrictions e.g
    Sep 08 for employee 22345 ,
    In one report it shows the Pay Scale level as A1 , then in the other report it shows Pay scale Scale level as A2  ,
    looking  at the master data in 0employee  , the first report is right ... this is how the data looks like in 0employee
    Employee  Valid from      To                Pay scale Level
    222345       2007-11-03   2008-09-30     A1
    222345       2008-10-01   9999-12-31     A2
    Can someone please shed some light on this , im thinking it has something to do with update rule but even that is supposed to use last date of the month , not 1st day of the following month. The Cube is a stndard cube 0PA_C01 and the update rule aswell .....

    Hi,
    Please check in the cube whether the data for the Employee is getting with two values like shown in your question:
    Employee Valid from To Pay scale Level
    222345 2007-11-03 2008-09-30 A1
    222345 2008-10-01 9999-12-31 A2
    and also check whether when the data loaded to the cube.
    There may be some change in the report structure where the difference is getting may in the column wise or row wise restriction may present.
    Please check on the structure of the report also.
    With Regards,
    Ravi Kanth

  • Linking two Queries but the values are corrupted

    I have started linking two queries from the same Cube.  The invoiced value from the pre-query shows the correct value from SAP.  When I use this prequery into another query and look at the same invoiced value key figure, the result has changed and is not correct anymore.  Please advise what I am doing wrong.
    Any help would be most appreciated.
    Ray

    Hi Bhanu, the replacement path is on the Dimension Sales Document.  I have tried to use the same variable on the Key Figure Net Value (Invoice).  I also tried for a later attempt to use a different Key Figure in the prequery as net weight, just in case they added together.
    Am I right that I should be using the same key figure Net Value (Invoice) in both queries?
    Thanks
    Ray

  • Drill down in report based on two queries

    Hi,
    I have a problem with drilling down in report which is based on two queries.
    Queries are based on different universes.
    Both queries contains almost the same dimensions but different measures.
    In my report is a calculated measure based on measures from both queries.
    In both universes are the same hierachies.
    When I drill down in report for the first time I have to chose hierarchy  but then data are filtered to the choosen  value only from one query , data from second query are not filtered and the values of calculated measure are incorrect
    How can I solve this issue without adding dimensions belonging to the hierarchies to queries.
    Please help.
    Regards.
    MG

    Hi MG,
    First of all, what do you mean by "Both queries contains almost the same dimensions but different measures"
    "Almost" is not a good word in the IT world, especially when trying to merge/join tables. You need to be exact.
    That sounds like a possible reason for the problem.
    I am also not sure about your question:
    "How can I solve this issue without adding dimensions belonging to the hierarchies to queries."
    You may have to add those dimensions to the queries. Why would you not want to?
    Thanks

  • Linking two switches together.

    hi Guys ,
    quick question in relation to joining two switches together,
    can I link a 2950 switch with a 1000 BASE-SX with a 3560G with 4 SPF ports with fibre and what pitfalls should i look out for .
    Thanks in advance
    Kevin

    Hello,
    So you would like to connect GBIC to SFP, you need Multimode Duplex Fiber Optical cable with SC-LC connectors. If SFP to SFP you need the same cably type with LC-LC connectors.
    http://www.cisco.com/en/US/products/hw/routers/ps341/prod_module_installation_guide09186a00801cc731.html
    http://cisco.com/en/US/products/hw/modules/ps5455/products_data_sheet09186a008014cb5e.html
    bye
    FCS
    Please rate me if I helped.

  • EA1 - Code formatting "squishes" multiple queries together

    If you have more than 1 query in an SQL Worksheet and you "Format" (CTRL-F7) the query, then it removes all blank lines and bunches all of the queries together.
    I would have expected it to leave a blank line after each ";" so that the individual queries can be easily identified.

    That's great news, thanks. I don't know if maybe I read your post a little wrong, but if I have this code:
    1 select * from dual;
    2
    3 select sysdate from dual;
    It currently formats as:
    1 select * from dual;
    2 select sysdate from dual;
    And if I read your post correctly, the new option will format it as:
    1
    2 select * from dual;
    3
    4 select sysdate from dual;
    Is that correct? I guess what I would really prefer is a blank line "between" any two (or more) SQL statements or PL/SQL blocks, but I'd be quite happy with a blank line "after" each block. Possibly the intended meaning was to have a blank line before each SQL statement, except for the first one. Is that correct?
    Greg.

  • Aligning subtotals from two queries.........

    I have two queries in a report that are identical except for one entry in the where clause. The two queries each have four groups and are linked by a column in the first group. Both queries return the same columns and a count value. My report displays the totals of each count by group. Each query brings back the expected results however the totals per group do not line up. How do I ensure that the total for each group in both queries line up together?
    Thanks in advance
    William

    Did you check both are same data type and doesn't have trailer spaces for either values?

Maybe you are looking for

  • Error while processing audit message

    hi I'm running a reconciliation, and throws me the following error . please help me ERROR,28 Aug 2009 03:50:32,492,[XELLERATE.AUDITOR],Error while processing audit message java.lang.NullPointerException at com.thortech.xl.audit.engine.AuditEngine.pro

  • Virus Scan of email attachments

    Can anybody help me in coding of Virus Scan of email attachments through java code, like we do with normal email engines like yahoo. Thanks in advance!!!

  • How to specify HTTPS endpoint for web role?

    We're using CloudService of Azure, and within there are two web roles (A and B), we hope both use HTTPS protocol. For web role A, we specify the endpoint like this: <Endpoints> <InputEndpoint name="WebPortalEndPoint" protocol="https" port="443" certi

  • Xquery Mapper

    Hi, I am done with the Xquery Mapper and have got an .xq file as an output. This .xq file takes an .xml as an input converts as defined in the Xquery tool. I have gone ahead and loaded this .xq file in the Aqualogic, which has provided with the funct

  • Form Templates will not save properly

    I have a few computers (All windows 7 64bit) that have recently been upgraded to Adobe XI 11.0.4.  2 of the computers are not able to save a form onto itself with changes.  One computer is.  To elaborate, if one user opens a form and fills out the fo