Multiple queries SQL

I am pretty new to this game. Can anyone help me with probably a very simple query.
I want to write a query which returns all rows from table 1, and also returns all rows from table 2, however there is no relationship between the tables. I want to view these in crystal reports, based upon their date field which I will also be recieving.
An example would be
SELECT * from tbl1
AND
SELECT * from tbl2
Any help would be really appreciated.

Hi,
You can present the results side by side.
Use the analytic ROW_NUMBER function to number the rows in each result set 1, 2, 3, ...
Outer join using that number.
For example:
WITH    dept_plus_rnum     AS
     SELECT     deptno
     ,     dname
     ,     ROW_NUMBER () OVER (ORDER BY dname)     AS rnum
     FROM     scott.dept
,     emp_plus_rnum     AS
     SELECT  ename
     ,     hiredate
     ,     job
     ,     ROW_NUMBER () OVER (ORDER BY ename)     AS rnum
     FROM     scott.emp
SELECT     d.deptno
,     d.dname
,     e.ename
,     e.hiredate
,     e.job
FROM           dept_plus_rnum     d
FULL OUTER JOIN      emp_plus_rnum     e     ON     d.rnum     = e.rnum
ORDER BY  d.rnum
,            e.rnum
;Output:
.   DEPTNO DNAME          ENAME      HIREDATE  JOB
        10 ACCOUNTING     ADAMS      23-MAY-87 CLERK
        40 OPERATIONS     ALLEN      20-FEB-81 SALESMAN
        20 RESEARCH       BLAKE      01-MAY-81 MANAGER
        30 SALES          CLARK      09-JUN-81 MANAGER
                          FORD       03-DEC-81 ANALYST
                          JAMES      03-DEC-81 CLERK
                          JONES      02-APR-81 MANAGER
                          KING       17-NOV-81 PRESIDENT
                          MARTIN     28-SEP-81 SALESMAN
                          MILLER     23-JAN-82 CLERK
                          SCOTT      19-APR-87 ANALYST
                          SMITH      17-DEC-80 CLERK
                          TURNER     08-SEP-81 SALESMAN
                          WARD       22-FEB-81 SALESMAN

Similar Messages

  • SQL Developer cannot execute multiple queries in one connection

    Hi,
    Using : SQL Developer 1.2.29.98, Oracle Database 9i on Windows XP.
    Currently I have TOAD and PL/SQL Developer to handle things related to Oracle Database.
    I found this SQL Developer tools as an interesting tool which might replace PL/SQL Developer (I assume).
    I opened two SQL Worksheets and tried to execute 2 queries (time consuming one) simultanously, suddenly it freezes (the window become grayed). Just like TOAD, we cannot smoothly execute multiple queries on single connection on SQL Developer
    I can monitor the query process using TOAD (Session Browser) and found both queries are running while SQL Developer window become grayed and seems not functioning. After the queries have been finished, I mean both of them, the SQL Developer window become normal and "alive" again showing the expected results.
    Well, however PL/SQL Developer could handle this. Executing multiple queries in single application is just its unbeatable features.
    We can view the query result once its finished instead of until the others being processed, by just only switch the SQL Windows.
    Is it true that SQL Developer doesn't support executing multiple queries?
    Or is it a feature which we should request?
    Or we have to activate this feature by doing some changes on configuration / preferences?
    (Do we need to open two SQL Developer instances? what a memory consuming solution).
    Regards,
    Buntoro

    SQLDeveloper connections are single threaded and also rather single minded (in that you can't do much else while a long query is running.)
    There is an existing feature request http://apex.oracle.com/pls/otn/f?p=42626:39:3685254426061901::NO::P39_ID:4202 for which you can vote.
    The workaround is to have multiple connections. Not brilliant but it works.

  • How to execute multiple queries in one stored procedure.

    Hi,
    I am Kumar,
    How to execute multiple queries in one stored procedure.
    here is the my requirements,
    1. get the max value from one table and sum of the that value.
    2. insert the values and also sum of the max value.
    using stored procedure
    I am using SQL server 2000 database.
    Please help me.
    Advance thanks
    by,
    Kumar

    This is not a java question and it is not even a problem: your only problem is
    1) lack of knowledge
    2) lack of interest to find a manual
    But you are going to have to change both by actually reading a book or a manual that explains the stored procedure language of SQL Server. It is the same as Sybase I think, so you could also look for a manual for that DBMS.

  • Multiple queries with 1 connection

    Can I execute multiple queries with one connection?
    //Example -
    <%
    String firstconn;
    Class.forName("org.gjt.mm.mysql.Driver");
    // create connection string
    firstconn = "jdbc:mysql://localhost/profile?user=mark&password=mstringham";
    // pass database parameters to JDBC driver
    Connection aConn = DriverManager.getConnection(firstconn);
    // query statement
    Statement firstSQLStatement = aConn.createStatement();
    String firstquery = "UPDATE auth_users SET last_log='" + rightnow + "'WHERE name='" + username + "' ";
    // get result code
    int firstSQLStatus = firstSQLStatement.executeUpdate(firstquery);
    // close connection
    firstSQLStatement.close();
    %>     
    Now, instead of building a new connection for each query, can I use the same connection info for another query?
    if so - how do you do this?
    thanks for any help.
    Mark

    Create multiple statement objects from your connection. It's a good idea to close these in a finally block after you're done with them
    Connection conn = null;
    Statement stmt1 = null;
    Statement stmt2 = null;
    try {
        conn = DriverManager.getConnection();
        stmt1 = conn.createStatement();
        // some sql here
        stmt2 = conn.createStatement();
        // some more sql here
    } finally {
        if ( stmt1 != null ) stmt1.close();
        if ( stmt2 != null ) stmt2.close();

  • Report with Multiple queries too slow in BI Publisher 11g

    Hi, I have a report in 11g where i need to create multiple queries to show them in report. I tried to combine everything in one query, but i found that the query is too huge and hard to understand and maintain. I created 3 data sets and linked them together. In SQL dev, the main query is returning about 315 records and first detail query returns less than 100 records and second detail query is returning one record which is BLOB. Each query returns data within a couple of seconds from SQL Developer. The entire report from BI Publisher should be just 21 page PDF output. Did anyone face performance issues while running reports with multiple queries in 11g? I ran reports that have single query which returned 10K pages PDF and never had an issue while everthing is in one query. This is the first time Iam attempting to create multiple queries. Can someone help me understand what i might be doing wrong or missing here. Thank you.

    Isn't there a way for you to do this via a Package/Procedure versus having multiple queries?
    Per the BI Publisher guide,
    Following are recommended guidelines for building data models:
    Reduce the number of data sets or queries in your data model as much as possible. In general, the fewer data sets and queries you have, the faster your data model will run. While multiquery data models are often easier to understand, single-query data models tend to execute more quickly. It is important to understand that in parent-child queries, for every parent, the child query is executed.
    You should only use multiquery data models in the following scenarios:
    To perform functions that the query type, such as a SQL query, does not support directly.
    To support complex views (for example, distributed queries or GROUP BY queries).
    To simulate a view when you do not have or want to use a view.
    Thanks,
    Bipuser

  • Question about templates with multiple queries

    I am just starting out with BI Publisher, v.10.1.3.2. I have a report that has multiple queries, but my template is just based on 1 query. How can I make the template use more than one query?
    Thanks!!

    <!-- BI Publisher Report Data Template --!>
    <!-- Report: -->
    <!-- defaultPackage - the PL/SQL package name to resolve any lexical
    references, group filters, or data triggers defined in the template. -->
    <dataTemplate name="dataTemplateName" description="DESCRIPTION" dataSourceRef="ORCL" defaultPackage="<SCHEMA>.<PACKAGE>" version="1.0">
    <properties>
    <property name="include_parameters" value="True|False"></property>
    <property name="include_null_Element" value="True|False"></property>
    <property name="xml_tag_case" value="upper|lower"></property>
    <property name="db_fetch_size" value="500"></property>
    <property name="scalable_mode" value="on|off"></property>
    <property name="include_rowsettag" value="true|false"></property>
    <property name="debug_mode" value="on|off"></property>
    </properties>
    <parameters>
    <parameter name="IDENTIFIER" dataType="character|date|number" defaultValue="0" include_in_output="true|false"></parameter>
    </parameters>
    <!-- Flexfield support for queries against Oracle Applications database -->
    <lexicals>
    <lexical></lexical>
    </lexicals>
    <dataQuery>
    <xml name="xml_query_name" expressionPath="Xpath_expression">
    <url method="GET|POST" realm="auth_name" username="" password="">file:///d:/windir/filename.xml</url>
    </xml>
    <sqlStatement name="query_name">
    <![CDATA[
    SELECT
    FROM
    WHERE
    ]]>
    </sqlStatement>
    </dataQuery>
    <!-- If you have multiple queries, you must link them to create the -->
    <!-- appropriate data output. In the data template, there are two methods -->
    <!-- for linking queries: using bind variables or using the <link> element -->
    <!-- to define the link between queries. -->
    <link parentQuery="parent_query_name" parentColumn="col" childQuery="child_query_name" childColumn="col" condition="= < <= > >="></link>
    <dataTrigger name="beforeReport" source="<package_name>.<function_name>"></dataTrigger>
    <!-- (Required for multiple queries) Defines the structure of the output -->
    <!-- XML. Consists of <group> and <element>elements to specify the -->
    <!-- structure. This section is optional for single queries; if not -->
    <!-- specified, the data engine will generate flat XML. -->
    <dataStructure>
    <group name="group_tag_name" source="query_name" groupFilter="<package_name>.<function_name>">
    <element name="tag_name" value="source_column" function="SUM() COUNT() AVG() MIN() MAX()"></element>
    <element name="tag_name" value="<group_name>.<column/alias name>" function="SUM() COUNT() AVG() MIN() MAX()"></element>
    <group name="group_tag_name" source="query_name" groupFilter="<package_name>.<function_name>">
         <element name="tag_name" value="source_column" function="SUM() COUNT() AVG() MIN() MAX()"></element>
         <element name="tag_name" value="<group_name>.<column/alias name>" function="SUM() COUNT() AVG() MIN() MAX()"></element>
    </group>
    </group>
    </dataStructure>
    <dataTrigger name="afterReport" source="<package_name>.<function_name>"></dataTrigger>
    </dataTemplate>

  • Multiple Queries  in Shared Components Report Queries

    Hey all,
    I am creating a report query which has multiple queries and I am running into to some issues with the builder.
    1.Whenever I try to edit a query it always sends me to the same query. (I can see that it is passing a different ID in the url, but the query never changes)
    - Ex: I create a report query and add two queries, SELECT 1 FROM DUAL and SELECT 2 FROM DUAL. no matter which querry i try to edit it always shows SELECT 1 FROM DUAL.
    2. There is no way to delete individual queries.
    - does anyone know a workaround to delete a query? (rather than just deleeting the entire report query)
    Cheers,
    Tyson Jouglet

    This was a bug that has been fixed in APEX version 3.2.1
    (its always helpful to list the version you are using along with your question)
    If you are using this with a BI publisher report layout, you will also get problems with earlier versions as the rowsets don't always get returned in the correct order.
    See this thread for more details....
    Bi Publisher result set question
    I ended up deleting my whole query and spending a long, careful afternoon adding the 33 queries I had in order one by one having made SURE they were all EXACTLY what I wanted using SQL Developer.
    Gus..
    You can reward this reply by marking it as either Helpful or Correct
    ;-)

  • Multiple queries without multiple tables?

    Greetings,
    Is there anyway I can choose between multiple queries and have the results come out on the one display table or do I have to have one display table per query?
    I'm thinking like having a dropdown list bound to queries and the results being displayed per selection.
    Many Thanks,
    Phil.

    I have this in _init() of myPage.java :
    myOwnRowSet.setDataSourceName("java:comp/env/jdbc/test1");
    myOwnRowSet.setCommand(getSessionBean1().getMethod());
    myOwnRowSet.setTableName("testTable");
    dataTable1Model.setCachedRowSet((javax.sql.rowset.CachedRowSet)getValue("#{myPage.myOwnRowSet}"));Then in the sessionbean getMethod()returns SQL query based on the input from user. In myPage.java i have the table already constructed and inside table I have hyperlink with link_action_method() that goes like this:
    getSessionBean1().setSomeMethod(""+getValue("#{currentRow['TRIP']}"));
    log("field's value is "+(String)getValue("#{currentRow['TRIP']}"));but in log I can see If i clicked let's say on 15th row it will store data in sessionbean not from 15th row of the table beeing displayed but from the 15th row from database! What am I doing wrong? Thx for your help,
    bojanidis
    See also http://forum.sun.com/jive/thread.jspa?threadID=104342&tstart=0

  • Multiple Queries Slower

    I am having an issue where the performance slows down drastically if i have multiple queries ( Running around 4 queries ) running at the same time. The performance is good when i have only one query running.
    When i run the queries individually one after an another it takes about 10 secs for each of them to return.
    When i run the queries together then it take more than a couple of minutes for all of them to return.
    Any tips suggestions for any changes in oracle parameters to improve performance, when multiple queries are running at the same time. Another thing, the CPU is not being used to its full capacity. The CPU is somewhere in the 10 to 20% usage.
    Thanks,
    Jay.

    Jayachandra, I think there is a good chance you need to tune one or more of the queries in question as they are probably running poorly using more resources than necessary. Individually they seem OK because total time is short but when combined the poor resource utilization is showing up.
    If running CBO
    run an explain plan on each query.
    update the statistics
    re-run the explain plans and look for differences
    If different retime the queries, you may already be done
    If not different or you spot something that looks wrong such as a full table scan where you think an index should be used then follow standard tuning practice to see what you can get.
    Then once you know the SQL are as good as they are going to get look at the buffer pool to make sure it is just not too small. Many DBA just immediately make the buffer pool bigger if query performance is not good enough, however, this is usually not the correct solution and I believe you should never over-allocate resources because you might need them somewhere else.
    HTH -- Mark D Powell --

  • A single OBIEE report firing Multiple Queries

    HI All,
    I tried the search option and did not find any questions which gives me what I am looking for. If I missed it and the question is already asked, please redirect me to the thread.
    I had a report which had a data issues. When i checked the log, I was shocked to see it firing 10 different queries. Could you guys please tell me exactly when OBIEE decides to split a single query and fire multiple ones?
    Here's some info on the report:
    1. All the columns are from the same subject area.
    2. All the physical tables are in the same database in the physical layer.
    3. All the tables are from the same physical catalog even.
    4. Majority of the columns are from the same fact. The fact table however has multiple LTS(Over 30) involving both fragmentation and content filters.
    Could you guys please let me know  why multiple queries are fired in the above case as well as generally by OBIEE?
    Thanks,
    Abhiram.

    It is recommended not to edit DB features. If you need to change them you might need to take help of oracle support.
    Else you might induce more erratic behavior.
    Not in agreement here. Depending on how that data sources beneath OBIEE are physically set up and parametrized you may be forced to change this in order to assure performance for example. Not all your BI-analyzed sources will be purpose-built for analytics and hence follow usual modellization rules or approaches. Oracle put the features in the DB objects for exactly that reason. And obviously you don't go and change the features "just like that".
    since fact measures are from multiple LTS, every time you bring a measure from different LTS it is treated as another star. So what OBIEE does is it queries each star separately using alias and then stitch them logically. Thats the reason for fragmented queries and a singel long sql in the end with stitches the other sql results in the end.
    True, but the OP was talking about "firing 10 different queries". Which is a bit vague but sounds more like distinct select statements rather than stich-joined WITHs...that's why I directed him towards the features which can actually change this dramatically. Problem is, that the OP hasn't made that exact point clear yet.

  • Matrix report with Multiple queries

    I have created one cross product group containing 4 subgroups under a single query. Now I have another one query seperately to be joined with the matrix query. Also I have one formula column and summary column with this the cross product group. The logic is if formula condition is true the it should take the 2nd query value in the place holder column otherwise it should take the first query value. is it possible?
    If any one knows about this update me ASAP to [email protected]

    Isn't there a way for you to do this via a Package/Procedure versus having multiple queries?
    Per the BI Publisher guide,
    Following are recommended guidelines for building data models:
    Reduce the number of data sets or queries in your data model as much as possible. In general, the fewer data sets and queries you have, the faster your data model will run. While multiquery data models are often easier to understand, single-query data models tend to execute more quickly. It is important to understand that in parent-child queries, for every parent, the child query is executed.
    You should only use multiquery data models in the following scenarios:
    To perform functions that the query type, such as a SQL query, does not support directly.
    To support complex views (for example, distributed queries or GROUP BY queries).
    To simulate a view when you do not have or want to use a view.
    Thanks,
    Bipuser

  • Cross tab data is getting multiplied if i use multiple queris in asingle report

    HI,
      i am using multiple queris for displaying data and graphs(charts).
      my requirement is to display 2 charts and data in crosstab in a single report.
      all the three thing (2charts and crosstab) will use diffrent values.
    I am writing 3 sql queries for getting appropriate values for charts and crosstab.
      Now the problem, both charts and crosstab are taking the values of all 3 queris
    i.e if i added crosstab  first to the report values are coming correctly. After  that if i add graph cross tab values are getting changed and graph values are not getting properly.
    if i add graph first then its coming correctly.
    if i tried to add all 3 components then values are going cores...... ?

    When you say you are writing 3 sql queries what do you mean? Are you creating 3 SQL command objects in the database expert? If so this is your problem, Crystal will pull a cartesian product through (this is every possible combinatin of rows from the 3 queries).
    If your 2 graphs and 1 crosstab are based on different datasets the way to approach this is to create each on a seperate report, then create a new blank report and add each of your 3 reports as subreports in the report footer.
    Hope this helps,
    Toby

  • Export multiple queries to Excel

    I am trying to export multiple queries to an excel file. How can i run multiple queries all in one go and then export them to an excel file?

    Unfortunately, you cannot do this from SQL Developer as it is at the moment - the only way I know of getting the results of multiple statements into one file without manual intervention is to run as a script, but this is useless for Excel once you have different columns or even widths. There is an "Accepted" feature request that seems to match what you want (link), but I don't know how soon it will be available in the product - maybe some extra votes might increase the priority).
    theFurryOne

  • Force Multiple Queries / "Stitching" in Union

    Is there any way to force OBIEE to execute several queries in parallel when combining several similar queries?
    For example, I have a very large fact table with monthly snapshot data. I would rather use combine with similar request option to send similar queries for each month and have OBIEE "stitch" them together. I have seen cases where multiple queries are sent do the database and other cases where one query is generated and sent to the database. Is there a way to force multiple queries to be sent?
    Ideally, what I'd like to be able to do is use my time dimension to send always force a query for each month (which is partitioned in the database).
    Edited by: user644029 on May 14, 2009 1:41 PM

    You don't need to do that because it's the work of the database.
    When you send a sql query to the database, the query is transformed to generate the best plan and it can be automatically parralelized (As you have partitions, I assume it's the case)
    To know more see the paragraph on the optimizer of the database.
    http://gerardnico.com/wiki/database/oracle/query_optimizer/start
    What about if the database have an aggregate/summary table ? You will send 10 query that can be done only in one.
    If you have a performance problem, try to decrease your selectivity by building an aggregate table and use the query rewrite. It's always the best solution.
    Obiee offer the aggregate persistence wizzard if you can't access to the database :
    http://knowledge.ciber.nl/weblog/?p=149
    Success
    Nico

  • Multiple Queries with JDBC

    Hello. I'm somewhat new to all of this, so forgive me if this is something really basic.
    I'm developing an application which must interact with my MySQL database pretty frequently, however it seems to me that I am unable to, essentially, have multiple ResultSets open at a given time, which as a result prevents me from making multiple queries simultaneously. The essential problem is...
    ResultSet rs = statement.execute( "SELECT * FROM table");
    if (rs.next())
        ResultSet srs = statement.execute( "SELECT * FROM table2");
        rs.getInt("id");
    }...Yields a NullPointerException on line 5. If I am correct in my understanding, this is due to a ResultSet closing when it's statement is used a second time.
    My best guess to solving this problem is to create a pool of statement objects (which would essentially be a number of connections to the DB), and then use the first open statement object (or a newly created one) to run a particular query... however this seems rather sloppy. Not to mention that, offhand, I'm not even sure if I can have multiple connections open to the DB at the same time. Is there any better way to run multiple queries at the same time with JDBC?
    Thanks in advance for any help.
    -Jess

    That's actually what I thought at first as well... given that a NPE is generally thrown along the lines of null.getMethod() however there is no null anywhere in my code, only a closed ResultSet... which returns an NPE on using a get method. For example:
    //our import
    import java.util.*;
    import java.sql.*;
    import javax.swing.JComponent.*;
    public class Server
            public static void main( String args[] ) throws Exception
                    try
                            //register driver
                            Class.forName("com.mysql.jdbc.Driver");
                            //location of database (including string to register unicode as utf-8
                            String dbUrl = "jdbc:mysql://localhost:1111/db_name?requireSSL=false&useUnicode=true&characterEncoding=UTF-8";
                            //create connection object
                            Connection mysqlConnection = DriverManager.getConnection(dbUrl,"username","password");
                            //autocommit
                            mysqlConnection.setAutoCommit(true);
                            //log information
                            System.out.println("Connected. Connection=" + mysqlConnection);
                            Statement mysqlStatement = mysqlConnection.createStatement();
                            mysqlStatement.execute("SELECT * FROM mud_index_players");
                            ResultSet rs = mysqlStatement.getResultSet();
                            if (rs.next())
                                    System.out.prinlnt("getInt() is " + rs.getInt("id"));
                                    mysqlStatement.execute("SELECT * FROM mud_table_stats");
                                    ResultSet rs2 = mysqlStatement.getResultSet();
                                    System.out.println("Now it's " + rs.getInt("id"));
                    catch ( ClassNotFoundException cnfe )
                            cnfe.printStackTrace();
                    catch ( Exception e )
                            e.printStackTrace();
    }Yields:
    Connected. Connection=com.mysql.jdbc.Connection@329f3d
    getInt() is 1
    java.lang.NullPointerException
            at com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:575)
            at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:930)
            at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:2507)
            at Server.main(Server.java:34)Where line 34 in Server.main is System.out.println("Now it's " + rs.getInt("id"));Thanks again for all your help!
    -Jess
    Message was edited by:
    [email protected]
    (Was missing some code tags)

Maybe you are looking for

  • Payment run - Paying company

    What settings are required when paying for more than one company so that a single payment is made to a vendor. Vendor number is the same in sending company codes. Also a single remittance advice is produced. Eg would be: Paying company code is 1000 s

  • Assets balance Report(T Cd s_alr_87011964) Not Tally with GL Code in FBL3N

    Hi Friends SAP Standard Assets balance Report(T Code s_alr_87011964 and s_alr_87011963 ) Not Tally with GL Code in FBL3N. In SAP report coming with Report Date but FBL3N coming with Posting Date So How I add Posting Date input parameter in Sap Standa

  • Formatted SD card with disk utility, broke the card.

    I just bought a 4GB SD card for my camera. At first it couldn't recognize it at all but when I connected the camera (with the card) to my mac and formatted it using Disk Utility app as 1GB plus free space the camera could work with the card. When I d

  • What are function modules used in alv,and its explanation

    what are function modules used in alv,and its explanation

  • Commitment Reporting and COOI table

    Experts, We have some PRs & POs that are being created and the commitment data can be viewed in table COOI, but we have some PRs and POs that don't show in COOI.  Is there a specific configuration or element to the PO that allows the commitment data