Where clause and joins
HI all,
If i Have a select statement that needs two different tables
and a where clause with only 1 join and the rest of conditions dependent on only 1 table such as:
select .... from table a, table b
where a.col1 = b.col1
and b.col2 some condition
and b.col3 some condition;
is it better/optima for performancel for me to have the join right at the beginning of the where clause or after table b has been filtered out such as:
select ... from table a, table b
where b.col2 some condition
and b.col3 some condition
and a.col1 = b.col1
Hi,
The order of conditions in a WHERE clause doesn't effect performance; the Cost-Based Optimizer will decide how to perform them.
The order can make a difference on how easy it is to understand and maintain the code. I find ANSI join syntax far better for this:
select ...
from table a
join table b on a.col1 = b.col1
where b.col2 <some condition>
and b.col3 <some condition>
;
Similar Messages
-
Where clause and order by to DAO classes
Hi
Is it ok(I mean design wise) to pass the 'where clause' conditions and order by clause as a parameter to the method of DAO class?Well, I would suggest you write seperate methods in your dao , one to select data without the where clause and one to select data with the where clause thrown in. If you have different 'where' clauses for selecting different kinds of data, have that many dao methods. The dao methods being specific know exactly what is the data that's coming in.
Lets assume you have a list of purchase orders and each purchase order is indetified by a unique id called PURCHASE_ORDER_ID.
1. The following code would populate a purchase order's details given an id.
private statis final String QUERY_1 = "select * from PURCHASE_ORDERS where PURCHASE_ORDER_ID = ? ";
PurchaseOrderModel getPurchaseOrderData(long poId){
//get a prepared statement from your connection
PreparedStatement pst = conn.prepareStatement(QUERY_1);
//set the poId passed as params to your query
pst.setLong(1, poId);
ResultSet rs = pst.executeQuery();
if(rs.next()){
//populate data into a model
finally{
//clean up resources
return model;
}2. The following code would return a list of PurchaseOrderModel's whose shipping date falls between a set of dates selected by the user.
private statis final String QUERY_2 = "select * from PURCHASE_ORDERS where SHIPPING_DATE between ? and ? ";
PurchaseOrderModel getPurchaseOrdersBetweenDates(list bindValues){
//get a prepared statement from your connection
PreparedStatement pst = conn.prepareStatement(QUERY_1);
//set the dates passed as params to your query
//we know that the List ought to contain only 2 dates
pst.setDate(1, (Date)bindValues.get(0));
pst.setDate(2, (Date)bindValues.get(1));
ResultSet rs = pst.executeQuery();
if(rs.next()){
//iterate and populate data into a model
//add model to a list
finally{
//clean up resources
return list;
3. This is more interesting - the dao method searches a list of Purchase Orders starting with a set of specific words. The words themselves may be one or many. This means that the number of '?' in your prepared statement may be dynamic. Each element of the list is a String that contains the start substring of a purcahse order name. For example - the list may contain elements like ["a", "ab", "c", "gh"] and the dao method returns all purchase order starting with these names.
private statis final String QUERY_3 = "select * from PURCHASE_ORDERS where ";
PurchaseOrderModel getPurchaseOrderNameMatches(list bindValues){
//construct the query dynamically
StringBuffer query = new StringBuffer(QUERY_3);
int count = 0;
for(Iterator itr = bindValues.iterator(); itr.hasNext();;){
String value = (String)itr.next();
query.append ("name like 'value%' ");
if (count != 0 and (count+1 != bindValues.length)){
query.append(" or ");
count ++;
//get a prepared statement from your connection
PreparedStatement pst = conn.prepareStatement(query.toString());
ResultSet rs = pst.executeQuery();
if(rs.next()){
//iterate and populate data into a model
//add model to a list
finally{
//clean up resources
return list;
To sum up,
1. You need as many methods as you have different kinds of searches (one method for each kind of 'where' clause).
2. The ejb/business layer would examine the data and decide on which method to call.
3. Increases coding effort, but makes the code clean and readable. Each layer does it's job. Thus we dont have ejbs forming 'where' clauses and so on.
Having said that, it really is your decision - you should take into consideration the following factors -
1. How big is the project ? If its a huge codebase developed by many people, then segregate the responsibilities clearly in each layer as I have outlined. For a small scale project, you could go with your approach.
2. Whats the take on maintenance and future add-ons ? Do you see the codebase growing with time ?
3. Is your project a commercial one - is it a product that needs to be maintained or is it a one-off development - develop once and you are done with it.
4. What are the design considerations ? Is somebody going to audit code for quality ? Or is it a academic one ?
You should take into account all these before deciding to go one way or the other.
A general thumb rule should be that you should be convinced that your code readable (maintainable), scalable and efficient. Anything that you do towards these ends is good code/design despite what people/books/patterns say, IMO.
cheers,
ram. -
Mutilple Filter Objects - Changing where clause and or
Is it possible to have a query as below using filter commands.
(obj1 = 'value11' and obj2 = 'value21')
or
(obj1 = 'value12' and obj2 = 'value22')
or
The objective is to manipulate the where clause and , or .
Thanks in Advance
Bhanu MohantyHi Bhanu,
to reach what you want it's necessary to build a virtual characteristic.
The new characteristic will be populated via coding during runtime of your query. Another possibility (as mentioned before in this forum by Siegfried Szameitat) is to create a new characteristic in your cube that contains field1 and field2 concatenated. With the first scenario, you dont need a reloading of your cube, with second one this is necessary.
Hope this helps.
Bye,
Roberto -
I have a selection screen like:
Table Field
EKKO EKORG
EKKO EKGRP
EKKO LIFNR
ESSR EBELN
ESSR EBELP
ESSR LBLNE
ESSR FRGZU
ESSR ERDAT
ESSR LOEKZ
Due to further complexities in the program i am joining 3 tables EKKO, EKPO and ESSR together. I can write the select stmt in 2 ways. I want to understand which one is better in terms of performance and is there exactly a rule here that i should follow before i write the where clause in this join.
SELECT aebeln bebelp alifnr aekorg aekgrp bpackno c~lblni
clblne cerdat cpackno cloekz cfrgsx cfrgkl c~frgzu
INTO TABLE gt_test
FROM ekko AS a INNER JOIN ekpo AS b
ON aebeln = bebeln
INNER JOIN essr AS c
ON aebeln = cebeln
AND bebeln = cebeln
AND bebelp = cebelp
WHERE a~lifnr IN so_lifnr
AND a~ekorg IN so_ekorg
AND a~ekgrp IN so_ekgrp
AND c~lblne IN so_lblne
AND c~ebeln IN so_ebeln
AND c~ebelp IN so_ebelp
AND c~erdat IN so_erdat.
SELECT aebeln bebelp alifnr aekorg aekgrp bpackno c~lblni
clblne cerdat cpackno cloekz cfrgsx cfrgkl c~frgzu
INTO TABLE gt_test
FROM ekko AS a INNER JOIN ekpo AS b
ON aebeln = bebeln
INNER JOIN essr AS c
ON aebeln = cebeln
AND bebeln = cebeln
AND bebelp = cebelp
WHERE a~ebeln IN so_ebeln
AND a~lifnr IN so_lifnr
AND a~ekorg IN so_ekorg
AND a~ekgrp IN so_ekgrp
AND b~ebelp IN so_ebelp
AND c~lblne IN so_lblne
AND c~erdat IN so_erdat.
AND c~erdat IN so_erdat.Hi,
This part is not necessary:
... a~ebeln = c~ebeln ...
Modify:
AND c~ebeln IN so_ebeln
AND c~ebelp IN so_ebelp
by
AND a~ebeln IN so_ebeln
AND b~ebelp IN so_ebelp
The best option will be:
if not so_ebeln[] is initial.
select ... where a~ebeln IN so_ebeln ... (2nd select)
else.
select ... where a~lifnr IN so_lifnr ... (1st select)
endif.
Also, you can try only the 2nd select, because it has WHERE clause to ebeln and lifnr. Depending on your database, you can check (via ST04) if the right index is selected (eg. if you inform so_ebeln the database must do the selection using ebeln index. if you inform so_lifnr the database must do the selection using lifnr index, etc..)
Best regards,
Leandro Mengue -
Using bind variable in dynamic where clause and concatenate with query
Hi,
In my procedure i am framing where clause dynamically with bind variable,When i am concatenate this with my sql query for REF CURSOR i got sql command not properly ended exception.
Is it possible to pass values to the bind variable through the dynamic variable/value?
Please advise
Thanks in advance
Siva
IF in_applicationId IS NOT NULL THEN
optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
END IF;
My query is like this
open Out_Main FOR SelectQuery USING optional_usingThanks for reply,
In my procedure, i suppose to frame the where clause with bind dynamically according to the input parameters. so that i am framing the values of the bind variables also dynamically like this,
Please advise...
IF in_assignedAppFlag IS NOT NULL THEN
IF in_assignedAppFlag = 'Y' THEN
optional_where := optional_where || ' AND b.ASSIGNED_TO = :b' ;
optional_using := ' in_appFuncGroup'||',in_currentUserID';
ELSe
IF in_isSupervisor = 0 THEN
optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
optional_using := ' in_appFuncGroup'||',in_currentUserID';
END IF;
END IF;
ELSE
IF in_isSupervisor = 0 THEN
optional_where := optional_where || ' AND (b.ASSIGNED_TO = :b'||' OR b.ASSIGNED_TO = ''-1'' OR b.ASSIGNED_TO IS NULL)';
optional_using := ' in_appFuncGroup'||',in_currentUserID';
END IF;
END IF;
IF in_appFuncGroup IS NOT NULL THEN
optional_where := optional_where || ' AND e.APP_FUNC_GROUP= :c';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup';
END IF;
IF in_queue_id IS NOT NULL THEN
optional_where := optional_where || ' AND b.QUEUE_ID = :d';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id';
END IF;
IF in_applicationId IS NOT NULL THEN
optional_where := optional_where || ' AND a.APPLICATION_ID like '||':e%';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'||',in_queue_id'||',in_applicationId';
END IF;
IF in_sourceCode IS NOT NULL THEN
optional_where := optional_where || ' AND e.APP_SOURCE_CODE like '||':f%';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
||',in_queue_id'||',in_applicationId'||',in_sourceCode';
END IF;
IF in_logo IS NOT NULL THEN
optional_where := optional_where || ' AND appProds.PRODUCT_TYPE like '||':g%';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo';
END IF;
IF in_firstName IS NOT NULL THEN
optional_where := optional_where || ' AND upper(a.FIRST_NAME) like upper(:h%)';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName';
END IF;
IF in_surName IS NOT NULL THEN
optional_where := optional_where || ' AND upper(a.SURNAME) like upper(:i%)';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName';
END IF;
IF in_retreival_id IS NOT NULL THEN
optional_where := optional_where || ' AND e.RETREIVAL_ID like :j%';
optional_using := ' in_appFuncGroup'||',in_currentUserID'||',in_appFuncGroup'
||',in_queue_id'||',in_applicationId'||',in_sourceCode'||',in_logo'||',in_firstName'||',in_surName'||',in_retreival_id';
END IF; -
How to use a lexical variable in a WHERE clause and as a function argument.
Hello,
My report has a lexical variable which has values like 'and id in (1,3,4)'. I want to use this variable in two separate queries. In the first, it is used in the WHERE clause, something like:
.. where date is not null &var;
In the second query, the variable is used in a function call, something like:
select * from table (my_function(&var));
The trouble is that the first query works when the value of the variable is unquoted, but for the second query the value should be quoted.
Does anyone have an idea how I could solve this problem?
Thanks in advance,
Frans
Message was edited by:
fransiehttp://tkyte.blogspot.com/2006/06/varying-in-lists.html
Presents many options. -
ADF/UIX where clause and VO on different pages
Hi,
i have a VO called Periods which contains Periods and their statuses. On one page for entering data i use the periods VO in LOV mode with a where clause limiting the user to selecting periods with open status.
I have another page which is for maintaining the period statuses. The problem is that when i move between entry and setup pages the where clause takes affect in both pages ie. the maintain periods page only shows periods with status Open!!
To get around this on the maintain periods prepare model i tried doing this:
actionContext.getBindingContainer().getApplicationModule().findViewObject("PeriodsView1").setWhereClause(null);
actionContext.getBindingContainer().getApplicationModule().findViewObject("PeriodsView1").executeQuery();this works, however it causes bizarre behaviour on some records when i change values in the UIX editable table. The UIX editable table works fine if i remove the above code snippet (and dont go to the page that sets the where clause on the view object). The behaviour is that i cant select some rows in the UIX table properly and the updated values arent effected.
can someone advise pn the proper way of doing this?Brenden, instead of setting the where clause to null, try setting it to an empty string (eg. "") or something dumb like "1=1".
In turn place JDeveloper into debug mode by selecting your project properties, profiles, development, runner, and changing the java options to: -Djbo.debugoutput=console
With this option turned on, you'll see your actual SQL going to the database with your where clause. You should be able to see the where clause of your underlying query that you just set, and if you use something dumb like 1=1 you'll note the setWhereClause module is working.
Hope this helps.
Cheers,
CM. -
Hi all,
How to use the where clause to select records based on condition,,,,, and this condition is based on a date,, for example:
select items from inventory_items
where purchasing_date in :from_date and :to_date;
Thank you very much
TasneemTasneem wrote:
Hi all,
How to use the where clause to select records based on condition,,,,, and this condition is based on a date,, for example:
select items from inventory_items
where purchasing_date in :from_date and :to_date;
Thank you very much
Tasneemtry this..
select items from inventory_items
where purchasing_date between :from_date and :to_date;
If someone's response is helpful or correct, please mark helpful or correct. -
I am creating a coditional query for one of my data blocks.
What I need to do is build a where clause on the fly and pass
that back to my block using the Set_BLock_Property built in. I
am able to do this but I am having problems with the fact that I
don't know how to correctly pass a date back. It seems when
specifying a date in a where clause it needs to have single
quotes around this. But when ever I try to embed the quotes in
the string I am not successful. I have even tried appending the
quotes using the chr function doing something like.
Where_Clause := 'Birthday <= 'Spencer,
I think chr(39) will give you the correct character. For example,
Where_Clause := 'Birthday <= ' -
LTS content WHERE clause and fitlers screwing up returned data
Hi all,
I'm connecting against Essbase 9.3.1 cubes with 10.1.3.4 and just stumbled upon an error. In some of the dimensions coming from Essbase there are undesired members, which I wanted to filter out the usual way. I.e. by adding where clauses to the LTS:
"Cube#1"."SALES".."SALES"."Gen4,Market" <> 'Dummy'
Now before doing this, everything runs fine with one report yielding this:
Gen3,Product Range
A 6.4
B 4
C 7.2
After adding:
Gen3,Product Range
A 35
B 110
C 42
These numbers don't make any sense. Funny thing is, that the request doesn't even display the Market dimension.
So I thought "well let's put it on the reports then". So I created saved filters (since there's also one on products)...Same result.
It actually appends this to the MDX
*set [Market4] as 'Filter(Generate({[Market3]}, Descendants([Market].currentmember, [Market].Generations(4),SELF), ALL), ( NOT ([Market].currentmember.MEMBER_ALIAS = "Corporate Sub-Region" OR [Market].currentmember.MEMBER_Name = "Corporate Sub-Region")) AND ( NOT ([Market].currentmember.MEMBER_ALIAS = "European Region SRgn" OR [Market].currentmember.MEMBER_Name = "European Region SRgn")))'*
The thing is: if I only use market dimension levels and filtering there I'm fine. Likewise, if I only use product dimension levels and filter on products there's no issue.
Any idea how I can filter this without getting errors?
Here's the two full statements
WORKS:
With
set [Data Type2] as 'Filter([Data Type].Generations(2).members, ([Data Type].currentmember.MEMBER_ALIAS = "Units" OR [Data Type].currentmember.MEMBER_Name = "Units"))'
set [Market3] as 'Filter([Market].Generations(3).members, ([Market].currentmember.MEMBER_ALIAS = "Europe" OR [Market].currentmember.MEMBER_Name = "Europe"))'
set [Product2] as 'Filter([Product].Generations(2).members, ([Product].currentmember.MEMBER_ALIAS = "SMU" OR [Product].currentmember.MEMBER_Name = "SMU"))'
set [Product3] as 'Generate([Product2], Descendants([Product].currentmember, [Product].Generations(3), leaves))'
set [Time Period2] as 'Filter([Time Period].Generations(2).members, ([Time Period].currentmember.MEMBER_ALIAS = "FY-09" OR [Time Period].currentmember.MEMBER_Name = "FY-09"))'
set [Time Period3] as 'Generate({[Time Period2]}, Descendants([Time Period].currentmember, [Time Period].Generations(3),SELF), ALL)'
set [View Type2] as 'Filter([View Type].Generations(2).members, ([View Type].currentmember.MEMBER_ALIAS = "Default" OR [View Type].currentmember.MEMBER_Name = "Default"))'
member [Account].[MS1] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market3]},{[View Type2]})),Account.[WoH Last 13Wks])', SOLVE_ORDER = 100
member [Account].[MS2] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market3]},{[View Type2]})),Account.[WoH Last 4Wks])', SOLVE_ORDER = 100
select
{ [Account].[MS1],
[Account].[MS2]
} on columns,
NON EMPTY {crossjoin ({[Product3]},{[Time Period3]})} properties ANCESTOR_NAMES, GEN_NUMBER on rows
from [SALES.SALES]
DOESNT WORK:
With
set [Data Type2] as 'Filter([Data Type].Generations(2).members, ([Data Type].currentmember.MEMBER_ALIAS = "Units" OR [Data Type].currentmember.MEMBER_Name = "Units"))'
set [Market3] as 'Filter([Market].Generations(3).members, ([Market].currentmember.MEMBER_ALIAS = "Europe" OR [Market].currentmember.MEMBER_Name = "Europe"))'
set [Market4] as 'Filter(Generate({[Market3]}, Descendants([Market].currentmember, [Market].Generations(4),SELF), ALL), ( NOT ([Market].currentmember.MEMBER_ALIAS = "Corporate Sub-Region" OR [Market].currentmember.MEMBER_Name = "Corporate Sub-Region")) AND ( NOT ([Market].currentmember.MEMBER_ALIAS = "European Region SRgn" OR [Market].currentmember.MEMBER_Name = "European Region SRgn")))'
set [Product2] as 'Filter([Product].Generations(2).members, ([Product].currentmember.MEMBER_ALIAS = "SMU" OR [Product].currentmember.MEMBER_Name = "SMU"))'
set [Product3] as 'Generate([Product2], Descendants([Product].currentmember, [Product].Generations(3), leaves))'
set [Time Period2] as 'Filter([Time Period].Generations(2).members, ([Time Period].currentmember.MEMBER_ALIAS = "FY-09" OR [Time Period].currentmember.MEMBER_Name = "FY-09"))'
set [Time Period3] as 'Generate({[Time Period2]}, Descendants([Time Period].currentmember, [Time Period].Generations(3),SELF), ALL)'
set [View Type2] as 'Filter([View Type].Generations(2).members, ([View Type].currentmember.MEMBER_ALIAS = "Default" OR [View Type].currentmember.MEMBER_Name = "Default"))'
member [Account].[MS1] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market4]},{[View Type2]})),Account.[WoH Last 13Wks])', SOLVE_ORDER = 100
member [Account].[MS2] as 'AGGREGATE(crossjoin ({[Data Type2]},crossjoin ({[Market4]},{[View Type2]})),Account.[WoH Last 4Wks])', SOLVE_ORDER = 100
select
{ [Account].[MS1],
[Account].[MS2]
} on columns,
NON EMPTY {crossjoin ({[Product3]},{[Time Period3]})} properties ANCESTOR_NAMES, GEN_NUMBER on rows
from [SALES.SALES]NLS is UTF8 btw.
-
WHERE clauses and Merge Join Cartesian?
For some reason, Siebel is generating queries like this:
AND CONCAT (CONCAT (t41828.lvl8anc_postn, '-'),
t41828.lvl8_emp_full_name
) = 'GEO-SMITH, BILL'
AND CONCAT (CONCAT (t41828.lvl6anc_postn, '-'),
t41828.lvl6_emp_full_name
) = 'GROUP1-DOE, JOHN'and this ends up with 3 merge join cartesian in autotrace and this query takes several hours.
However, by rewriting just those 2 clauses to:
AND (t41828.lvl8anc_postn = 'GEO' and
t41828.lvl8_emp_full_name = 'SMITH, BILL')
AND (t41828.lvl6anc_postn = 'GROUP1' and
t41828.lvl6_emp_full_name = 'DOE, JOHN')the merge join cartesians go away, and it runs in 7 seconds.
However, since Siebel is generating the query, and we are having issues, we decided to add columns for testing that is equivalent to the concatenation of the two columns above. After doing this, and creating indexes on the new columns, it is now back to the merge join cartesian and I cannot get rid of it.
So:
1. How can rewriting the WHERE (not adding or deleting anything here, just rewriting it in a different way) clause eliminate the merge join cartesian?
I'm guessing by understanding that single question, I will be able to come up with a better solution to this.Note we made two additional columns:
CONCAT (CONCAT (t41828.lvl8anc_postn, '-'), t41828.lvl8_emp_full_name) => col1 CONCAT (CONCAT (t41828.lvl6anc_postn, '-'), t41828.lvl6_emp_full_name) => col2
When I created indexes on col1 and col2 and used them in the query, the cartesians returned, and I cannot figure out why. So, I'm still confused why:
In the original query:
1. Using CONCAT, and thus no indexes => cartesian
2. No CONCAT, and indexes => no cartesian
With the new columns, col1 and col2:
1. No CONCAT needed, full table scan or indexes => cartesian -
I have an inventory table.
I want to do the following query to determine
how many systems have no category assigned to them.
select count(hostname) from systable where category is null;
It seems I can only create this statement if
hostname is replaced by category but then you can't do a count on a null.....I can get it to display in a popup
by just getting all rows displayed where
category is null and then clicking on
Sheet --> Count All Rows.
But I'd like to include it in a Discover
generated report.
Mike
---- -
WHERE clause creating a join for two or more tables
The CS3 Dreamweaver book says that the WHERE clause can
create a join for two or more tables. The join was created, but the
data is repeating. I have searched the web and this forum and have
not found the answer.
My Master page filters the recordset by Style No and when a
customer clicks on a particular style, it sends him to the Detail
page. All the records are showing from all tables on the detail
page from the Dynamic List, except they are showing multiple times
(ex. Size table has 4 sizes and Color table has 2 colors - my Size
Drop Down list is showing 8 options and my Color Drop Down List is
showing 8 options) I have a Master Page with a recordset pointing
to a Detail Page using the same recordset.
Master page works perfectly.
Master Recordset SQL:
SELECT products.itemID, products.category, products.styleno,
products.name, products.description, products.ourprice,
products.imageTH, products.image, coloroption.color,
sizeoption.size
FROM products, coloroption, sizeoption
WHERE category = 'chefcoats' AND
products.styleno=sizeoption.styleno AND
products.styleno=coloroption.styleno
GROUP BY products.styleno
ORDER BY styleno ASC
The Detail Recordset:
SELECT products.itemID, products.category, products.styleno,
products.name, products.description, products.ourprice,
products.imageTH, products.image, sizeoption.size,
coloroption.color
FROM products, sizeoption, coloroption
WHERE itemID=colname AND products.styleno=sizeoption.styleno
AND products.styleno=coloroption.styleno
I tried using the GROUP BY on the detail page, but then it
only showed one size and color from the dynamic drop down list. I
tried changing the field name "styleno" in the other tables to be
unique, however, I was using the table identifer. I tried using the
JOIN command instead of the WHERE clause and that didn't help
either.
On the detail page, the customer is supposed to click on the
Size box and see sizes XSM - 6XL ONLY ONE TIME. and then be able to
click on the Color option and see White, Black, Red ONE TIME.
Is this possible?
Thank you for giving your time to read this.!
EvieDo you have a link we can look at to see what you are trying
to do?
Dave
"EviePhillips" <[email protected]> wrote in
message
news:[email protected]...
> The CS3 Dreamweaver book says that the WHERE clause can
create a join for
two
> or more tables. The join was created, but the data is
repeating. I have
> searched the web and this forum and have not found the
answer.
>
> My Master page filters the recordset by Style No and
when a customer
clicks on
> a particular style, it sends him to the Detail page. All
the records are
> showing from all tables on the detail page from the
Dynamic List, except
they
> are showing multiple times (ex. Size table has 4 sizes
and Color table has
2
> colors - my Size Drop Down list is showing 8 options and
my Color Drop
Down
> List is showing 8 options) I have a Master Page with a
recordset pointing
to a
> Detail Page using the same recordset.
>
> Master page works perfectly.
> Master Recordset SQL:
> SELECT products.itemID, products.category,
products.styleno,
products.name,
> products.description, products.ourprice,
products.imageTH, products.image,
> coloroption.color, sizeoption.size
> FROM products, coloroption, sizeoption
> WHERE category = 'chefcoats' AND
products.styleno=sizeoption.styleno AND
> products.styleno=coloroption.styleno
> GROUP BY products.styleno
> ORDER BY styleno ASC
>
> The Detail Recordset:
> SELECT products.itemID, products.category,
products.styleno,
products.name,
> products.description, products.ourprice,
products.imageTH, products.image,
> sizeoption.size, coloroption.color
> FROM products, sizeoption, coloroption
> WHERE itemID=colname AND
products.styleno=sizeoption.styleno AND
> products.styleno=coloroption.styleno
>
> I tried using the GROUP BY on the detail page, but then
it only showed
one
> size and color from the dynamic drop down list. I tried
changing the
field
> name "styleno" in the other tables to be unique,
however, I was using the
table
> identifer. I tried using the JOIN command instead of the
WHERE clause and
that
> didn't help either.
>
> On the detail page, the customer is supposed to click on
the Size box and
see
> sizes XSM - 6XL ONLY ONE TIME. and then be able to click
on the Color
option
> and see White, Black, Red ONE TIME.
>
> Is this possible?
>
> Thank you for giving your time to read this.!
> Evie
>
> -
Where clause on right side table of a left join
I was told by someone that a where clause on the right side table of a left join is bad SQL. I have looked around and found a great article for DB2. I am not sure if this is 100% correct for SQL Server so would like to find a good detailed
article on the topic.
Thank youI was told by someone that a where clause on the right side table of a left join is bad SQL. I have looked around and found a great article for DB2. I am not sure if this is 100% correct for SQL Server so would like to find a good detailed
article on the topic.
Thank you
I'm going to be blunt here so if you get offended easily please stop reading now.
That has got to be some of the dumbest advice I've seen in a while. Such a query serves a specific purpose, there's no good or bad to it. Following is a classic example:
select distinct
CustomerID
from Customer as c
left join Orders as o
on c.CustomerID = o.CustomerID
and o.OrderDate > dateadd(day, -90, getdate())
where o.CustomerID is null
The above hypothetical query, which includes a where clause which targets the right table in a left join, returns all customers which have not placed an order in the past 90 days. It's a perfectly valid query which serves a key business purpose and
I challenge anyone to justify why they claim it is "bad SQL".
Such a query will execute efficiently given appropriate indices. There's simply no justification for such a blanket statement about where clauses and outer joins. -
How to avoid repeat where clause in oracle sql
Hi,
Please find my query below, I need a help to avoid duplication of **where** clause in my query.
In my below query, **JOIN** condition is same for both the queries and **WHERE** condition also same except this clause "and code.code_name="transaction_1"
In **IF ** condition only credit and debit is swapped on both queries, due to this **Credit and Debit** and this where clause "and code.code_name="transaction_1" I am duplicating the query. Can you please give some solution to avoid this duplication. I am using oracle 11g
select DAY as business_date,sum(amount) as AMOUNT, type_amnt as amount_type,test_code as code_seg
from
select table1_alias.date as DAY,code.code_numb as test_code,
CASE
WHEN qnty_item > 0 THEN 'credit'
ELSE 'debit'
END as type_amnt,
"25.55" as amount
from
code_table code,
table1 table1_alias
join table2 table2_alias on table1_alias.id = table2_alias.id
where
table1_alias.state="OK"
and table1_alias.type="R"
and code.code_type="Movie"
and code.code_name="transaction_1"
UNION ALL
select table1_alias.date as DAY,code.code_numb as test_code,
CASE
WHEN qnty_item > 0 THEN 'debit'
ELSE 'credit'
END as type_amnt,
"25.55" as amount
from
code_table code,
table1 table1_alias
join table2 table2_alias on table1_alias.id = table2_alias.id
where
table1_alias.state="OK"
and table1_alias.type="R"
and code.code_type="Movie"
and code.code_name="transaction_2"
group by DAY, test_code,type_amnt
Thanksuser10624672 wrote:
Hi,
Please find my query below, I need a help to avoid duplication of **where** clause in my query.
In my below query, **JOIN** condition is same for both the queries and **WHERE** condition also same except this clause "and code.code_name="transaction_1"
In **IF ** condition only credit and debit is swapped on both queries, due to this **Credit and Debit** and this where clause "and code.code_name="transaction_1" I am duplicating the query. Can you please give some solution to avoid this duplication. I am using oracle 11g
select DAY as business_date,sum(amount) as AMOUNT, type_amnt as amount_type,test_code as code_seg
from
select table1_alias.date as DAY,code.code_numb as test_code,
CASE
WHEN qnty_item > 0 THEN 'credit'
ELSE 'debit'
END as type_amnt,
"25.55" as amount
from
code_table code,
table1 table1_alias
join table2 table2_alias on table1_alias.id = table2_alias.id
where
table1_alias.state="OK"
and table1_alias.type="R"
and code.code_type="Movie"
and code.code_name="transaction_1"
UNION ALL
select table1_alias.date as DAY,code.code_numb as test_code,
CASE
WHEN qnty_item > 0 THEN 'debit'
ELSE 'credit'
END as type_amnt,
"25.55" as amount
from
code_table code,
table1 table1_alias
join table2 table2_alias on table1_alias.id = table2_alias.id
where
table1_alias.state="OK"
and table1_alias.type="R"
and code.code_type="Movie"
and code.code_name="transaction_2"
group by DAY, test_code,type_amnt
ThanksA very brief glance and it looks to me like the only difference between the 2 queries are
and code.code_name="transaction_1"In the first portion and
and code.code_name="transaction_2"So if that's all that is difference, you'd just want to use a single query (no union's) with
and code.code_name in ('transaction_1', 'transaction_2')Cheers,
Maybe you are looking for
-
How can i have '&' in EXECUTE IMMEDIATE statement?
I have PL/SQL procedure, where i will be inserting data to a table. Data which i am inserting is having a '&' value in it. If i use the below statement for insert then sqlplus is prompting for the value '&' like a substitution value while compile thi
-
Hi everyone, I saw a note today on ML, which says that new 11g's feature - [Extended statistics|http://download.oracle.com/docs/cd/B28359_01/server.111/b28274/stats.htm#sthref1177] - is partially available in 10.2.0.4. See [Bug #5040753 Optimal index
-
My system.log is filling up with these: postfix/smtpd[22148]: warning: 57.223.192.81.relays.ordb.org: RBL lookup error: Host or domain name not found. Name service error for name=57.223.192.81.relays.ordb.org type=A: Host not found, try again Just st
-
I'm trying to reinstall the cs6 but it says the serial number is not valid
why i can't reinstall my CS6?
-
Using laptop on separate home and office wireless networks
I have a laptop the connects (wireless) to my home router and my other home computers. At work we have a wireless router (both home and office are linksys wrt54g's). I can connect to the router at work, get to the internet, but can't "see" the other