How to do a Nested Query ?
I have three Tables Student, Courses, Marks
Table : Student
Columns
StudentID <PK>
First Name
Last Name
Table : Grades
Columns
StudentID <FK>
Grade
Table : Courses
Columns
StudentID <FK>
CourseID
CourseDesc
Now to get all the course descriptions which this particular student is taking based on the StudentID we do something like this :
SELECT c.courseDesc
FROM Courses c, Student s
WHERE s.StudentID = '100'
AND s.StudentID = c.StudentID
The above will work
But If I need to do it in nested query how can I do it : Something like
SELECT * FROM
SELECT c.courseDesc
FROM Courses c, Student s
AND s.StudentID = c.StudentID
WHERE s.StudentID = '100'
Thanks for the help.
Harsimrat
oops,try this...
SELECT * FROM (
SELECT s.StudentID,c.courseDesc
FROM Courses c, Student s
WHERE s.StudentID = c.StudentID)
WHERE StudentID = '100';
SQL> select * from
2 (select e.ename,d.deptno from test_dept d,test_emp e where e.deptno = d.deptno)
3 where deptno = 10;
ENAME DEPTNO
BLAKE 10
CLARK 10
KING 10
MILLER 10
SQL>
Similar Messages
-
Nested query / Rank in ODI 10g?
How can be an nested query with analytical function (RANK() OVER) can be implemented in ODI 10g without using an external view?
SELECT field1, field2, field3, field4, field5, field6, field7
FROM
(SELECT
RANK() OVER (PARTITION BY table1.field1, table1.field2, table1.field3 ORDER BY table1.field4 , table1.field5) alias_rank,
field1, field2, field3, field4, field5, field6, field7
FROM table1
) subset_alias
WHERE subset_alias.alias_rank=10)You should get your answers from here
http://www.business-intelligence-quotient.com/?tag=oracle-data-integrator-subqueries -
Hi,
What is a nested query? Can anyone give me an example of how to create a nested query? Please expain me in detail with an example?
Thanks
RaniHi,
nested query is like one querys result is used as a input to second query.it is sort of a replacement path char variable filled by a query result is used for a char restriction in one query. Restriction is somewhat like Top N. Returned set of values is used for a restriction in the 2nd query.
Assume that in Query X, a characteristic A returns values 1,2,3. (Master data of A may be 1,2,3,4.....)
In another Query Y, you want to restrict char A to only those values that are returned in Query X, in our example its 1,2 & 3. To achieve this, you will create a replacement path variable on char A in Query Y, in the process it will ask you to give the query name, which will be Query X
For nested "If "condition in Bex Formula's:
http://help.sap.com/saphelp_nw2004s/helpdata/en/23/17f13a2f160f28e10000000a114084/frameset.htm
Regards
CSM Reddy -
I have a table that has id, category_parent and
category_name. How can I write a query so that I can get nested
<ul> as follwing:
<ul id="nav">
<li> <a href="#" >first Level menu</a>
<ul>
<li><a href="#" >second Level
menu</a></li>
<li><a href="#" >second Level menu</a>
<ul>
<li><a href="#" >third Level
menu</a></li>
</ul>
</li>
</ul>
</li>
</ul>
Please help!!
-AHi,
I think Ken Ford's solution will work for 2 levels only.
We need to use recursive function. I made the sampe. It will work for n levels.
I used a static data for this example. I assumed first level menu contain parent id as 0.
My code:
<!---<cfquery name="request.menu" datasource="#dsn#">
select id, category_parent, category_name from menu menuTable
</cfquery>--->
<cfscript>
q = QueryNew('id,category_parent,category_name');
newRow = QueryAddRow(q, 4);
QuerySetCell(q, "id", "1", 1);
QuerySetCell(q, "category_parent", "0", 1);
QuerySetCell(q, "category_name", "First Level -1", 1);
QuerySetCell(q, "id", "2", 2);
QuerySetCell(q, "category_parent", "0", 2);
QuerySetCell(q, "category_name", "First Level -2", 2);
QuerySetCell(q, "id", "3", 3);
QuerySetCell(q, "category_parent", "0", 3);
QuerySetCell(q, "category_name", "First Level -3", 3);
QuerySetCell(q, "id", "4", 4);
QuerySetCell(q, "category_parent", "2", 4);
QuerySetCell(q, "category_name", "second Level -1", 4);
request.menu = q;
</cfscript>
<cffunction name="getChilds">
<cfargument name="pId">
<cfquery name="qChilds" dbtype="query">
select * from request.menu
where category_parent = <cfqueryparam value="#arguments.pId#" cfsqltype="cf_sql_bigint">
</cfquery>
<cfif qChilds.recordCount gt 0>
<cfoutput query="qChilds">
<ul>
<li><a href="##">#category_name#</a></li>
#getChilds(id)#
</ul>
</cfoutput>
<cfelse>
<cfreturn>
</cfif>
</cffunction>
<cfoutput>#getChilds(0)#</cfoutput> -
Hi All,
How to get the physical SQL query for the OBIEE reports.
Thanks in advance,
Haree.Hi Anitha,
Thanks for your reply,
I am getting XML script in log file. (Settings > Administration > Manage Sessions > View Log).
How to get physical SQL query ?
Thanks,
Haree -
How to tune past SQL query??
Hi Team,
Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
I am working on 10.2.0.4 version DB..
How to trace an sql query after its execution?? pls provide steps how to begin with..
regards
dkoracledkoracle wrote:
Hi Team,
Straight to issue --> I am seeing an query running for long time. When i begun to trace that particular query it got over by the time and now how to trace that specific SID and QUERY..
I am working on 10.2.0.4 version DB..
How to trace an sql query after its execution?? pls provide steps how to begin with..Can not be done.
ALTER SESSION SET SQL_TRACE=TRUE;
-- run query again -
How to Create a Functiona Query
Dear all,
Could any body detail me how to create a functional query. Please give me step by step procedure to create a query.
I would appreciate if you can give me a material with screen shots. Your help will be highly appreciated.
Thank you
Raghu RamHi Raghu,
Go through this document it may help you,
SAP Query
Step 1: Create User Group SQ03
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > User Groups
a) In the User Group: Initial Screen -
Enter User Group Code (self named)
Click on Create
b) In the User Group (Code): Create or Change pop-up window -
Enter the User Group Description
Click on Save
c) In the Create Object Directory Entry pop-up window -
Ö Click on Local Object button
Ö The User Group Created is saved
Step 2: Create User Group SQ02
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > Infosets
a) In the Infoset: Initial screen -
Ö Enter Infoset Code (self named)
Ö Click on Create button
b) In the Infoset: Title & Database Screen -
Ö Enter Description of Infoset in the Name field
Ö In the Data Source selection: Select appropriate Data Source by clicking
the radio button
· Source the data can either be multiple tables OR single table. There are 4
options for the user to select from
Ö Click on Continue (Enter)
Ö Selected Table gets displayed in the Infoset : Initial Screen
c) In the Infoset: Initial Screen -
Ö Click on Insert Table button
d) In the Add Table Screen -
Ö Enter the Table Name that is to be inserted
Ö Click Continue (Enter)
e) In the Infoset: Initial Screen -
Ö Click on Back button
f) In the Field Group Defaults pop-up Screen -
Ö Select Appropriate Field Group Option by clicking on the radio button
· there are 3 options to select from. User can select Empty Field Group
option and then select the data fields in the steps explained further.
Alternatively, User can select an option which clubs all the data fields
From all the tables selected
Ö Click Continue (Enter)
g) In the Change Infoset Screen -
· the left side lists the Tables that the user has selected in step b, c & d
· In the right side, system creates field groups, one for each table listed in the
left part. Initially, the Field Groups are empty
Ö In the Left Side, Click on the arror next to the table name and expand and
display all the data fields in the table
Ö Select a Data Field from the expanded Table view, which is to be added to
the Field Group on the right.
Ö Select a Field Group on the right side, in which Data Field selected above
has to be added
Ö Right click on the Data Field selected and click on Add Field to Field Group
Ö The selected Data Field gets added to the selected Field Group, which is
indicated by an arrow next to the Field Group.
Ö Carry out the steps above to add the required Data Fields to the respective
Field Groups
Ö After transferring Data Fields to Field Groups click on Generate button
h) In the Create Object Directory Entry Screen -
Ö Click on Logical Object button to generate the infoset
i) In the Change Infoset Screen -
Ö Click on the Back button
j) User is taken back to the Infoset: Initial Screen which displays the
created Infoset record.
Step 3: Assigning User Group to Infoset SQ03
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > User Groups
a) In the User Groups: Initial screen -
Ö Enter the User Group for which Infoset is to be assigned
Ö Click on Assign Users & Infosets button
b) In the User Group: Assign Users Screen -
Ö Click on Assign Infosets button
c) In the next screen, select the Infoset, which needs to be attached to the
User Group selected
d) Click on the Back button
Step 4: Creating Query SQ00 & SQ01
Follow the menu path SAP Menu > Tools > ABAP Workbench > Utilities > SAP Query > Queries
a) In the Query from User Group: Initial Screen -
Ö Click on Other User Groups button
Ö In the pop-up screen, User Groups, select the User Group for which the
Query has to created. The pop-up screen closes.
Ö Enter the Query Code in the Query field
Ö Click on Create button
b) A pop-up screen Restrict Value Range shows the list of Infosets assigned to
the User Group
Ö Select the Infoset for which Query has to be created
c) In the new screen Create Query: Title, Format -
Ö Enter the Description of the Query in the Title field
Ö Click on the Next Screen button
d) In the Select Field Group screen
Ö Select the Field Groups from which Data Fields have to be selected for the
Output
Ö Click on the Next Screen button
e) In the Select Field screen -
Ö Select the Data Fields, which should appear in the output
Ö Click on the Next Screen button
f) In the Screen Selection -
Ö Select the Data Fields for the selection criteria
Ö Enter the sequence in which the selected fields would appear in the input
screen of the query.
Ö Define if the selection criteria should be Single Value or Multiple Value Range
by clicking in the appropriate check boxes
Ö Click on the Basic List button
g) In the screen Query Layout Design -
Ö Select the Output Fields from the Data Fields section by clicking the
appropriate check box
Ö Change the sequence of Data Field columns if required
Ö Click on the Test button to test the query created
h) On the Test Query screen click Continue
i) In the Query screen -
Ö Enter the selection criteria
Ö Click on Execute button
j) Save the Query created
Step 5: Running the Query SQ00
a) In the Query From User Group: Initial screen
b) Click on Other User Groups button to select the User Group
c) In the pop-up screen User Groups select the User Group
d) System lists all the queries created for the User Group
e) Select the appropriate Query
f) Click on Execute button
g) User is taken to the Selection screen
h) Enter the selection criteria and click on Execute button
i) System runs the query and gives the output
Regards,
Murali. -
How to view the sql query?
hi,
how to view the sql query formed from the xml structure in the receiver jdbc?You can view SAP Note at
http://service.sap.com/notes
But you require SMP login ID for this which you should get from your company. The content of the notes are as follows:
Reason and Prerequisites
You are looking for additional parameter settings. There are two possible reasons why a feature is available via the "additional parameters" table in the "advanced mode" section of the configuration, but not as documented parameter in the configuration UI itself:
Category 1: The parameter has been introduced for a patch or a SP upgrade where no UI upgrade and/or documentation upgrade was possible. In this case, the parameter will be moved to the UI and the documentation as soon as possible. The parameter in the "additional parameters" table will be deprecated after this move, but still be working. The parameter belongs to the supported adapter functionality and can be used in all, also productive, scenarios.
Category 2. The parameter has been introduced for testing purposes, proof-of-concept scenarios, as workaround or as pre-released functionality. In this case, the parameter may or may not be moved to the UI and documentation, and the functionality may be changed, replaced or removed. For this parameter category there is no guaranteed support and usage in productive scenarios is not supported.
When you want to use a parameter documented here, please be aware to which category it belongs!
Solution
The following list shows all available parameters of category 1 or 2. Please note:
Parameter names are always case-sensitive! Parameter values may be case-sensitive, this is documented for each parameter.
Parameter names and values as documented below must be used always without quotaton marks ("), if not explicitly stated otherwise.
The default value of a parameter is always chosen that it does not change the standard functionality
JDBC Receiver Adapter Parameters
1. Parameter name: "logSQLStatement"
Parameter type: boolean
Parameter value: true for any string value, false only for empty string
Parameter value default: false (empty String)
Available with: SP9
Category: 2
Description:
When implementing a scenario with the JDBC receiver adapter, it may be helpful to see which SQL statement is generated by the JDBC adapter from the XI message content for error analysis. Before SP9, this can only be found in the trace of the JDBC adapter if trace level DEBUG is activated. With SP9, the generated SQL statement will be shown in the details page (audit protocol) of the message monitor for each message directly.
This should be used only during the test phase and not in productive scenarios.
Regards,
Prateek -
How to write a sql query to retrieve data entered in the past 2 weeks
Hi,
I have file names and last accessed date(java.sql.Date format) stored in my database table, I would like to know how I can write a query to get the name of files accessed in the past 2 weeks,I use open sql server at the back end.
Thanks in advance.This has essentially nothing to do with JDBC. JDBC is just an API to execute the SQL language using Java and thus interact with the databases.
Your problem is related to the SQL language, you don't know how to write the SQL language. I suggest you to go through a SQL tutorial (there is one at w3schools.com) and to read the SQL documentation which come along with the database in question. A decent database manfacturer has a website and probably also a discussion forum / mailinglist as well.
I'll give you a hint: you can just use equality operators in SQL like everywhere. For example: "WHERE date < somedate". -
How to write a SQL query in SAP B1 2007 B with input parameters?
How to write a SQL query in SAP B1 2007 B with input parameters, on execution of which will ask for some input value from the user and the values will be selected from a list such as item list?
The syntax like
SELECT * FROM OITM T0 WHERE T0.ItemCode = '[%0\]'
Thanks,
Gordon -
How to transport the BW query's variable to BO webi report
Hi all
I'd like to know how to transport the BW query's variable to BO 's webi . today ,I created a sap customer varible in my bw system to get the max calmonth in the active table.The varible in the BW side run's well ,but I use this query to build a new univers ,and created a new webi report base on this univers ,but the question is the webi report can't get the varible's value I wann to know how to transport the bw varible value to BO webi report
Thanks and regards,
Peter .zhuI have changed my variaable in my bw query ,I found if you use SAP default variable it is ok in BO side . So I get a guidline by SAP default variable ,I changed my customer variable in variables edite ,don't use 'ready for input' .And then the variable can be useful in BO side .
Edited by: peter zhu on Jun 16, 2008 11:43 AM -
How I can change this query, so I can display the name and scores in one r
How I can change this query, so I can add the ID from the table SPRIDEN
as of now is giving me what I want:
1,543 A05 24 A01 24 BAC 24 BAE 24 A02 20 BAM 20in one line but I would like to add the id and name that are stored in the table SPRIDEN
SELECT sortest_pidm,
max(decode(rn,1,sortest_tesc_code)) tesc_code1,
max(decode(rn,1,score)) score1,
max(decode(rn,2,sortest_tesc_code)) tesc_code2,
max(decode(rn,2,score)) score2,
max(decode(rn,3,sortest_tesc_code)) tesc_code3,
max(decode(rn,3,score)) score3,
max(decode(rn,4,sortest_tesc_code)) tesc_code4,
max(decode(rn,4,score)) score4,
max(decode(rn,5,sortest_tesc_code)) tesc_code5,
max(decode(rn,5,score)) score5,
max(decode(rn,6,sortest_tesc_code)) tesc_code6,
max(decode(rn,6,score)) score6
FROM (select sortest_pidm,
sortest_tesc_code,
score,
row_number() over (partition by sortest_pidm order by score desc) rn
FROM (select sortest_pidm,
sortest_tesc_code,
max(sortest_test_score) score
from sortest,SPRIDEN
where
SPRIDEN_pidm =SORTEST_PIDM
AND sortest_tesc_code in ('A01','BAE','A02','BAM','A05','BAC')
and sortest_pidm is not null
GROUP BY sortest_pidm, sortest_tesc_code))
GROUP BY sortest_pidm;
Hi,
That depends on whether spriden_pidm is unique, and on what you want for results.
Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements, relevamnt columns only) for all tables, and the results you want from that data.
If you can illustrate your problem using commonly available tables (such as those in the scott or hr schemas) then you don't have to post any sample data; just post the results you want.
Either way, explain how you get those results from that data.
Always say which version of Oracle you're using.
It looks like you're doing something similiar to the following.
Using the emp and dept tables in the scott schema, produce one row of output per department showing the highest salary in each job, for a given set of jobs:
DEPTNO DNAME LOC JOB_1 SAL_1 JOB_2 SAL_2 JOB_3 SAL_3
20 RESEARCH DALLAS ANALYST 3000 MANAGER 2975 CLERK 1100
10 ACCOUNTING NEW YORK MANAGER 2450 CLERK 1300
30 SALES CHICAGO MANAGER 2850 CLERK 950On each row, the jobs are listed in order by the highest salary.
This seems to be analagous to what you're doing. The roles played by sortest_pidm, sortest_tesc_code and sortest_test_score in your sortest table are played by deptno, job and sal in the emp table. The roles played by spriden_pidm, id and name in your spriden table are played by deptno, dname and loc in the dept table.
It sounds like you already have something like the query below, that produces the correct output, except that it does not include the dname and loc columns from the dept table.
SELECT deptno
, MAX (DECODE (rn, 1, job)) AS job_1
, MAX (DECODE (rn, 1, max_sal)) AS sal_1
, MAX (DECODE (rn, 2, job)) AS job_2
, MAX (DECODE (rn, 2, max_sal)) AS sal_2
, MAX (DECODE (rn, 3, job)) AS job_3
, MAX (DECODE (rn, 3, max_sal)) AS sal_3
FROM (
SELECT deptno
, job
, max_sal
, ROW_NUMBER () OVER ( PARTITION BY deptno
ORDER BY max_sal DESC
) AS rn
FROM (
SELECT e.deptno
, e.job
, MAX (e.sal) AS max_sal
FROM scott.emp e
, scott.dept d
WHERE e.deptno = d.deptno
AND e.job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY e.deptno
, e.job
GROUP BY deptno
;Since dept.deptno is unique, there will only be one dname and one loc for each deptno, so we can change the query by replacing "deptno" with "deptno, dname, loc" throughout the query (except in the join condition, of course):
SELECT deptno, dname, loc -- Changed
, MAX (DECODE (rn, 1, job)) AS job_1
, MAX (DECODE (rn, 1, max_sal)) AS sal_1
, MAX (DECODE (rn, 2, job)) AS job_2
, MAX (DECODE (rn, 2, max_sal)) AS sal_2
, MAX (DECODE (rn, 3, job)) AS job_3
, MAX (DECODE (rn, 3, max_sal)) AS sal_3
FROM (
SELECT deptno, dname, loc -- Changed
, job
, max_sal
, ROW_NUMBER () OVER ( PARTITION BY deptno -- , dname, loc -- Changed
ORDER BY max_sal DESC
) AS rn
FROM (
SELECT e.deptno, d.dname, d.loc -- Changed
, e.job
, MAX (e.sal) AS max_sal
FROM scott.emp e
, scott.dept d
WHERE e.deptno = d.deptno
AND e.job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY e.deptno, d.dname, d.loc -- Changed
, e.job
GROUP BY deptno, dname, loc -- Changed
;Actually, you can keep using just deptno in the analytic PARTITION BY clause. It might be a little more efficient to just use deptno, like I did above, but it won't change the results if you use all 3, if there is only 1 danme and 1 loc per deptno.
By the way, you don't need so many sub-queries. You're using the inner sub-query to compute the MAX, and the outer sub-query to compute rn. Analytic functions are computed after aggregate fucntions, so you can do both in the same sub-query like this:
SELECT deptno, dname, loc
, MAX (DECODE (rn, 1, job)) AS job_1
, MAX (DECODE (rn, 1, max_sal)) AS sal_1
, MAX (DECODE (rn, 2, job)) AS job_2
, MAX (DECODE (rn, 2, max_sal)) AS sal_2
, MAX (DECODE (rn, 3, job)) AS job_3
, MAX (DECODE (rn, 3, max_sal)) AS sal_3
FROM (
SELECT e.deptno, d.dname, d.loc
, e.job
, MAX (e.sal) AS max_sal
, ROW_NUMBER () OVER ( PARTITION BY e.deptno
ORDER BY MAX (sal) DESC
) AS rn
FROM scott.emp e
, scott.dept d
WHERE e.deptno = d.deptno
AND e.job IN ('ANALYST', 'CLERK', 'MANAGER')
GROUP BY e.deptno, d.dname, d.loc
, e.job
GROUP BY deptno, dname, loc
;This will work in Oracle 8.1 and up. In Oracle 11, however, it's better to use the SELECT ... PIVOT feature. -
How can I create a query with tables in INFOSET?
Dear Gurus,
How can I create a query with tables in INFOSET?
Just tables and fields INFOSET?
Kind Regards,Hello
Check following SCN Article for your understanding/reference:
- [Using Infoset Query ,SAP Query and Quick Viewer|http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/10eab7af-0e54-2c10-28a5-87b47adbe1a5]
Regards
JP -
How can I create a query with web service data control?
I need to create a query with web service data control, in WSDL, it's query operation, there is a parameter message with the possible query criteria and a return message contains the results. I googled, but cannot find anything on the query with web service. I cannot find a "Named Criteria" in web service data control like normal data control. In Shay's blog, I saw the topics on update with web service data control. How can I create a query with web service data control? Thanks.
Hi,
This might help
*054. Search form using ADF WS Data Control and Complex input types*
http://www.oracle.com/technetwork/developer-tools/adf/learnmore/index-101235.html -
How can I get a query in the search field to open in a new tab or new window from the current window?
If you are searching via the Search Bar on the Navigation Toolbar, this preference can be changed to have searches there open in a Tab.
Type '''about:config''' in the Address Bar and hit Enter. Then answer "I'll be careful". Type this pref in the Search at the top.
'''browser.search.openintab''' = double-click to toggle to '''true'''
Maybe you are looking for
-
I read the first suggested article before posting this question, but it wasn't specific enough so I was forced to comment, "This article fails to specify use of the backed up file in the event of a system/HDD reformat." The article reveals that the p
-
Dreamweaver MX 2004 with Contribute CS3
Good Afternoon, I have Adobe CS3 Web Premium edition, but a colleague located interstate is using DreamWeaver MX 2004. I would like him to design a dreamweaver template for use in Contribute CS3. Are there any known compatibility issues with doing th
-
Can anyone tell me how to click the sphere and display a messege???
/* Goal: Want to create a bunch of spheres, and when a sphere is clicked: * 1) display a message in the textfield * 2) transform the position of the sphere to (0,0,0) * (if (0,0.0) is occupied by another sphere, move that sphere somewhere. * Achieved
-
Gmail, Mozilla etc. blocked!
After updating another program I can't now access some websites including Google and Mozilla! For Google and Mozilla it allowed be to select:- 'I understand the risks' ad continue. But for Gmail it showed no option to continue! As all was working bef
-
Hi, I have created bunch of users in the Central system. How do I copy these users to the child systems? Please let me know. Thanks Seelan