How to write SQL hints for this query?
The query is like:
select * from foo, t
where foo.name in
(select name from bar
where id in (
select id from car
where date < sysdate
and foo.a = t.b;
I want the innermostsubquery 'select id from car ...' to be executed first, and the subquery 'select name from bar ...' to be execute second, and the outermost query 'select * from foo,t ...' to be executed the last. How can I write the Oracle sql hints to force the order?
Thanks.
user553560
You might be able to create a large set of hints to force the access path you want - but unless you really know what you are doing with hints, you may find that your solution is very unstable (it might be luck rather than correctness that let's it work to start with).
The difficulty in this query is the double layer of IN subqueries, so if you can rewrite the query, you might try manually unnesting as follows:
select
t1.*. t.*
from
select
distinct t2.name
from t2
where t2.id in (
select t3.id
from t3
where t3.dated < sysdate
) v,
t1,
t
where
t1.name = v.name
and t1.a = t.bDepending on your indexing and statistics, you may find that a simple /*+ unnest */ hint in the first subquery will be sufficient to do this for your. Again depending on the statistics you may find that you have to put extra hints into the above to make Oracle use the join method and indexes you think appropriate.
N.B. The first step (as others have noted) is to check that your statistics are good before you start manipulating the code or using hints.
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
Similar Messages
-
How to write Select statement for this codition
I need to check whether SGTXT contains BELNR value.
SGTXT is a text field and It should be matched with BELNR
How to write select statement for this.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT should have the given BELNR Value.
Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.Hi,
data temp(12).
concatenate '%' belnr '%' into temp.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT like temp.
If belnr is having multiple values,just create a internal table as follows.
types : begin of ty,
belnr....
temp(12),
end of ty.
data itab_ type standard table of ty.
data wa type ty.
loop at itab into wa.
concatenate '%' wa-belnr '%' into wa-temp.
modify itab from wa index sy-tabix transporting temp.
endloop.
Change your select statement accordingly.
Kindly reward poits if it helps. -
How to write a PCR for this ?
Hi SAP-HR Experts .
Dear friends , My Company Requires a specific requiremnt that at the date of any Employee's
B'day his one day salary should get doubled and he is entitled to get one leave on his B'day .
I do not know how to write a PCR for this ?
May some Body tell me how to meet this requirement Please .
tell me please step by step how to go through ...
It will be great help for me .
Best regards : rajneeeshI think you can make it with something like this:
Write a PCR in schema, you can call the rule with "actio";
000860 ACTIO 9BIR AR Birthday
Rule 9BIR
9BIR Rule for Birthday
NUM=FG C Set " F (fixed indicator for deadline calculation); G (Birth date from infotype 0002);C (complete months)
NUM/12 División " Number of completed months divided by 12
NUMV0O2L Off.Lng en arg.var. " the last two places of the number are entered in the variable argument.
" if the rest is not 00, there is nothing to do
00 " if the rest is 00
ZERO= N AmtNumRteZeit = 0 "
AMT= 1002 Set " wagetype of salary
AMT/TKDIVI División " divides the amount by Partial Period Parameter Whole Month
ADDWTI1002 Input table " accumulates into 1002
Example: an employee with birthday 01.01.1977 in IT0002
Payrroll in january 08
wagetype 1002 before rule 9BIR:
3 1002 Salario Bas01 30,33 30,00 909,90
Rule 9BIR
NUM=FG C Set; NUM= 372
NUM/12 ; 372/12= 31 rest=00
AMT=1002 ; AMT= 909,90
AMT/TKDIVI ; 909,90/31= 29,35
ADDWTI1002 ; 909,90 + 29,35= 939,25
wagetype 1002 before rule 9BIR:
3 1002 Salario Bas01 30,33 30,00 939,25
Hope this helps. Manuel -
How to write customer exist for Keyfigure( query )
Hi gurus,
I have to write customer exist for a key figure.
Please tell me how to write it.
Thanks,
JamesPankesh,
SE24 is for defining classes .. are you sure this is for customer exits ?..
Use a formula variable filled by a customer exit... go to TCode CMOD and follow the normal procedure for defining Exits.. look up the forums for detailed steps on how to write an exit..
Arun
Hope it helps... -
How to write a class for this?
how do i write a different class for this? how do i implement the "a.add(b)"? it code is to test basic arithmetic operations.
System.out.print ("Arithmetic: enter two integer numbers: ");
Integer a = new Integer (Integer.parseInt(kbd.readLine()));
Integer b = new Integer (Integer.parseInt(kbd.readLine()));
System.out.println (a + "+" + b + "-" + b + "*" + a + "/" + a + "%" + b + " is: " + a.add(b).sub(b).mul(a).div(a).rem(b));public class arthOperation{
add()
sub()
sub(){
mul()
mul(){
div()
div(){
rem()
rem(){
is it write? -
How to write a DTD for this scenario?
hi,
consider the following xml
<set after = "A">
<item name="A" ></item>
<item name="B" ></item>
</set>
The DTD for the "item" element is
<!ATTLIST item name (A | B| C| D| E ) #REQUIRED >
The attribute "after" of "set" can hold a single valid name like
<set after = "A">
or
a collection of valid names seperated by coma like <set after = "A,B,C">
how to write DTD for the "after" attibute such that it will contain a single valid name or collection of names?
Regards,
Ajay.I could be wrong, but I'm pretty sure that DTD doesn't support that. You're probably better off declaring the name attribute to be of type PCDATA and tokenizing the value manually in code.
-
How to write Sql statement for M:M relationship set?
If theres two Entity sets "Department" and "Employee".....
Department Entity contains this attribute dno,dname,address etc and
"Employee" entity contain attribute like Empno,Empname,date,time etc
and theres Many to Many relationship between Employee and Deapartment Entity set,i.e.each employee can work in any department, and each department has at least one employee (Many to Many relationship)
What should be the SQL statement to create table for Many to Many relationship sets for Employee and Department set..
Any helps will be appreciated.
Femicreate 3 tables: employee, department and empdept
in the empdept table you reference foreign keys from the 2 other tables. so if my employee id was 42 and I work for departments 1,2 and 3, this table would look like this:
emp_fk | dept_fk
42 1
42 2
42 3 -
How to do SQL Command for this
Hi,
I have 2 tables.
TempTT TempTB
Name Place DeviceName Products
Factory_55 Indonesia Factory_55##11122 Pencils
Factory_22 USA Factory_22##23444 Pens
Factory_33 UK Factory_22##82922 Erasers
How do I do my SQL command if I wanted to extract DeviceName from TempTB
if TempTT.Name is found in TempTB.DeviceName??
Please advise me. Thank you!!I do not want to join them. I show my table here again. I wanted to SELECT DeviceName from TempTB if the Name from TempTT is found in DeviceName of TempTB. Thanks alot!
TempTT
Name Place
Factory_55 Indonesia
Factory_22 USA
Factory_33 UK
TempTB
DeviceName Products
Factory_55##11122 Pencils
Factory_22##23444 Pens
Factory_22##82922 Erasers -
How do I use count for this query?
How do I display all the addresses in a table that have more than one (or >1) account number? I wasn't sure how or if I should use count along with group by and having to get the expected results.
select address from tablename
group by address having count(1) > 1; -
How to write Error message for select options?
Hi
i have this select option statement
SELECT-OPTIONS: s_fevor FOR afko-fevor.
how to write error message for this?
Regards
SmithaError messages are displayed for Select-options mostly on two conditions:
1) You needs to check wether a value is entered or not its done by:
a)
Select-options:SELECT-OPTIONS: s_fevor FOR afko-fevor Obligatory.
In this case error message is automatically throwed by system.
b) You can do this in Selection Screen events.
Ex:
AT SELECTION-SCREEN./AT SELECTION-SCREEN ON S_FEVOR.
IF S_FEVOR-LOW IS INITIAL.
MESSAGE 'XXXXX' TYPE 'E'.
ENDIF.
2) You need to Validate the entered value:
You can do this in Selection Screen events.
Ex:
AT SELECTION-SCREEN./AT SELECTION-SCREEN ON S_FEVOR.
SELECT FEVOR
FROM AFKO
INTO AFKO-FEVOR
UP TO 1 ROWS
ENDSELECT.
IF SY-SUBRC NE 0.
MESSAGE 'XXXXX' TYPE 'E'.
ENDIF.
Regards,
Gurpreet -
How to write sql query for counting pairs from below table??
Below is my SQL table structure.
user_id | Name | join_side | left_leg | right_leg | Parent_id
100001 Tinku Left 100002 100003 0
100002 Harish Left 100004 100005 100001
100003 Gorav Right 100006 100007 100001
100004 Prince Left 100008 NULL 100002
100005 Ajay Right NULL NULL 100002
100006 Simran Left NULL NULL 100003
100007 Raman Right NULL NULL 100003
100008 Vijay Left NULL NULL 100004
It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains both left_leg and right_leg id, then it is called pair.)
I know there are three pairs under id "100001" :-
1. 100002 and 100003
2. 100004 and 100005
3. 100006 and 100007
100008 will not be counted as pair because it does not have right leg..
But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005Sounds like this to me
DECLARE @ID int
SET @ID = 100001--your passed value
SELECT left_leg,right_leg
FROM table
WHERE (user_id = @ID
OR parent_id = @ID)
AND left_leg IS NOT NULL
AND right_leg IS NOT NULL
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
How to write sql query for below mentioned eaxmple.
Hi,
I have requirement.
There are number of rows and I need the result through query as follows.Please help me to proved sql query for below mentioned requirement.
example: table TEST.
COLA COLB COLC COLD COLE COLF MANAGER 5 NULL NULL 3 NULL
SR.MANAGER 6 3 NULL NULL NULL
VP 5 5 4 5 5
I have to write the sql query if COLA IS MANAGER THEN CONSIDER MANGER RECORD,AND IF ANY COLUMN FILED IS NULL FOR MANGER THEN CONSIDER COLA IS SR.MANGER, AND IF ANY COLUMN FILED IS NULL FOR SR,MANGER THEN CONSIDER VP records.
I need output as below.
COLB COLC COLD COLE COLF
5(manager) 3(sr.manger) 4(vp) 3(manger) 3(vp)
Please provide the for above mentioned output.
ThanksDuplicate thread. please view the answer posted in your first thread.
how to write sql query.
And, please don't post any duplicate thread.
Regards.
Satyaki De. -
How to write sql query with many parameter in ireport
hai,
i'm a new user in ireport.how to write sql query with many parameters in ireport's report query?i already know to create a parameter like(select * from payment where entity=$P{entity}.
but i don't know to create query if more than 1 parameter.i also have parameter such as
$P{entity},$P{id},$P{ic}.please help me for this.
thanksYou are in the wrong place. The ireport support forum may be found here
http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=showcat&catid=9 -
How will write SQL query to fetch data from each Sub-partition..
Hi All,
Anyone does have any idea about How to write SQL query to fetch data from Sub-partition.
Actually i have one table having composite paritition(Range+list)
Now if i want to fetch data from main partition(Range) the query will be
SELECT * FROM emp PARTITION(q1_2005);
Now i want to fetch data at sub-partition level(List) .But i am not able to get any SQL query for that.
Pls help me to sort out.
Thanks in Advance.
AnwarSELECT * FROM emp SUBPARTITION(sp1);
-
Is there a way to create a plan guide for this query?
How can i create a plan guide for this query,suppose i can't change the query text:
USE AdventureWorks2008R2;
GO
SET NOCOUNT ON;
GO
-- query plan statement starts
DECLARE @Group nvarchar(50), @Sales money;
SET @Group = N'North America';
SET @Sales = 2000000;
SET NOCOUNT OFF;
SELECT FirstName, LastName, SalesYTD
FROM Sales.vSalesPerson
WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;
-- query plan statement ends
AdventureWorks2008R2's parameterization option is simple, i want this type of query can reuse plan:
DECLARE @Group nvarchar(50), @Sales money;
SET @Group = N'Other Country';
SET @Sales = 88;
SET NOCOUNT OFF;
SELECT FirstName, LastName, SalesYTD
FROM Sales.vSalesPerson
WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;
I tried many times ,but it didn't work:
declare @xml nvarchar(max) -- the plan i want to reuse
set @xml = (select cast (query_plan as nvarchar(max))
from sys.dm_exec_query_plan (0x060006001464570B405D92620200000001000000000000000000000000000000000000000000000000000000))
-- create plan guide
exec sp_create_plan_guide
@name ='Test'
,@stmt=N'SELECT FirstName, LastName, SalesYTD
FROM Sales.vSalesPerson
WHERE TerritoryGroup = @Group and SalesYTD >= @Sales;'
,@type =N'sql'
,@params =N'@Group nvarchar(50), @Sales money'
,@hints = @xml;
Thanks.I guess you don't wanna fire these queries "adhoc" but prepared instead to reuse the plan:
exec sp_executesql N'SELECT FirstName, LastName, SalesYTD FROM Sales.vSalesPerson WHERE TerritoryGroup = @Group and SalesYTD >= @Sales',
N'@Group nvarchar(50), @Sales money', N'Other Country',88
exec sp_executesql N'SELECT FirstName, LastName, SalesYTD FROM Sales.vSalesPerson WHERE TerritoryGroup = @Group and SalesYTD >= @Sales',
N'@Group nvarchar(50), @Sales money', N'North America',2000000
Bodo Michael Danitz - MCT, MCITP - free consultant - performance specialist - www.sql-server.de
Maybe you are looking for
-
Sender File Adapter stop processing all files
Hello all, the file adapter pick up all files in the directory by default. if a large number of files are in the directory then this could slow down the pi processing. is there any way to process only one file per polling?? regards
-
Time Capsule as HD for Bootcamp?
I just bought the Time Capsule thinking I could use it as an External Hard Drive with Bootcamp (windows 7 on iMac 27 inch), I've been searching all over the internet with no luck, please help me. Additional question: 1.- Is there a way to connect the
-
Xslt code - adding suffix value
Hello SAP experts, May we seek advise from you on a working xslt code for adding suffix? Source: 012345 Target: 012345HELLO The suffix 'HELLO' will be placed at the end of the value. Please advise. Thanks! Gerberto!
-
Stuck on 'Media Pending' PP CC 2014 8.0
After the first import of all my MXF files into Premiere Pro CC 2014, it's now stuck on 'Media Pending' since I reopened the project. Cleared cache etc to no avail, seems to be a common issue but I haven't came across a solid fix yet, anyone else hav
-
My iPod can't plays music on the right headphone
Hi I am having some problems with my I put any headphones or speakers in the headphone jack it only plays on the left side while the right side stays quiet. Also the headphone jack seems to be looser because I can jiggle the connector of my headphone