joining 2 tables help
table oneMACHINE DATE_START, DATE_END
-------------------------------------------------------------------------
M5 11/10/10 13:00 11/10/10 18:00
table b
PRODUCTION_DAY DATE_START, DATE_END MACHINE UPDATE
----------------------------------------------------------------------------------------------------------
11/10/2010 11/10/10 13:30 11/10/10 14:30 M5 1
11/10/10 14:30 10/11/10 17:30 M5 1
11/10/10 17:30 10/11/10 18:00 M5 1
11/10/10 18:00 11/10/10 19:00 M5 1
Is there a way to join the 2 tables above, based on the machine and date_start.
tableA has always 1 record and table B has several records for the record in table A.
Try this:
IM assuming your table A will be only a start for one machine per day. For the same machine from table one you will have several times start and end in table B.
Select * from table a, table b where to_char(a.DATE_START,'J') = to_char(B.DATE_START,'J') and a.MACHINE = b.MACHINE
This query you will get all the child records of table B based on the DATE_START (just the date, excluding timestamp) of table A.
to_char(a.DATE_START,'J') returns a number that is unique for the given day.
Ex: Select double to_char(sysdate,'J');
Let me know how you go with it.
Tags: Database
Similar Questions
-
So that to joining 3 tables make me 2 ranks, real, I need only one line
Hi all
While joining 3 tables make me 2 rows, I need 1 row.
Please find my request and the actual output and the expected results.
Help me handle this.
Select
-MFU_D_C_INVESTOR_ID_DET,
mfu_remove_junk (Q.CAN) CAN_ST,
mfu_remove_junk (Q.INSTALLMENT_AMOUNT) AMOUNT_ST,
mfu_remove_junk (x.Can) can be,
mfu_remove_junk (x.Amc_Code) Amc_Code,
mfu_remove_junk (x.Folio_No) Folio_No,
mfu_remove_junk (x.Order_Status) Order_Status,
mfu_remove_junk (x.User_Code) User_Code,
mfu_remove_junk (x.User_Txrn_No) User_Txrn_No,
mfu_remove_junk (x.Group_Ord_No) Group_Ord_No,
mfu_remove_junk (x.Ind_Txn_Ref_No) Ind_Txn_Ref_No,
mfu_remove_junk (x.Pending_Txn_Ref_No) Pending_Txn_Ref_No,
mfu_remove_junk (x.Appl_No) Appl_No,
mfu_remove_junk (x.Ts_Machine_Id) Ts_Machine_Id,
mfu_remove_junk (x.Trxn_Date) Trxn_Date,
mfu_remove_junk (x.Trxn_Time) Trxn_Time,
mfu_remove_junk (x.Timestamp_No) Timestamp_No,
mfu_remove_junk (x.Sch_Code) Sch_Code,
mfu_remove_junk (x.Reinv_Tag) Reinv_Tag,
mfu_remove_junk (x.Txn_Mode) Txn_Mode,
mfu_remove_junk (x.Trxn_Type) Trxn_Type,
mfu_remove_junk (x.Sub_Trxn_Type) Sub_Trxn_Type,
mfu_remove_junk (x.Units) units,
mfu_remove_junk (x.Amount) amount.
mfu_remove_junk (x.All_Units_Flag) All_Units_Flag,
Entity_Id, mfu_remove_junk (x.Entity_Id),
mfu_remove_junk (x.ENTITY_BRANCH_ID) ENTITY_BRANCH_ID,
mfu_remove_junk (x.Location) location,
(TO_CHAR(sysdate,'DD-MON-RRRR')) CREATED_DATE
Of MFU_FTP_XML_FILES T
Left Join Xmltable ('/ COMM_TXN_STRUCT/FILE_ROWS/FILE_ROW ')
By the way T.Filecontent
Columns
-MFU_D_C_INVESTOR_ID_DET
Can Varchar2 (500) path ' INVESTOR_ID_DET / CAN'.
Path of Varchar2 (500) Amc_Code "INVESTOR_ID_DET/AMC_CODE,"
Path of Varchar2 (500) Folio_No "INVESTOR_ID_DET/FOLIO_NO,"
Path of Varchar2 (500) Order_Status ' TRANSACTION_DET/ORDER_STATUS. "
Path of Varchar2 (500) User_Code "TRANSACTION_DET/USER_CODE,"
Path of Varchar2 (500) User_Txrn_No "TRANSACTION_DET/USER_TXRN_NO,"
Path of Varchar2 (500) Group_Ord_No "TRANSACTION_DET/GROUP_ORD_NO,"
Path of Varchar2 (500) Ind_Txn_Ref_No "TRANSACTION_DET/IND_TXN_REF_NO,"
Path of Varchar2 (500) Pending_Txn_Ref_No "TRANSACTION_DET/PENDING_TXN_REF_NO,"
Path of Varchar2 (500) Appl_No "TRANSACTION_DET/APPL_NO,"
Path of Varchar2 (500) Ts_Machine_Id "TRANSACTION_DET/TS_MACHINE_ID,"
Path of Varchar2 (500) Trxn_Date "TRANSACTION_DET/TRXN_DATE,"
Path of Varchar2 (500) Trxn_Time "TRANSACTION_DET/TRXN_TIME,"
Path of Varchar2 (500) Timestamp_No "TRANSACTION_DET/TIMESTAMP_NO,"
Path of Varchar2 (500) Sch_Code "TRANSACTION_DET/SCH_CODE,"
Path of Varchar2 (500) Reinv_Tag "TRANSACTION_DET/REINV_TAG,"
Path of Varchar2 (500) Txn_Mode "TRANSACTION_DET/TXN_MODE,"
Path of Varchar2 (500) Trxn_Type "TRANSACTION_DET/TRXN_TYPE,"
Path of Varchar2 (500) Sub_Trxn_Type "TRANSACTION_DET/SUB_TRXN_TYPE,"
Units Varchar2 (500) Path TRANSACTION_DET/UNITS"."
Amount Varchar2 (500) path ' TRANSACTION_DET/AMOUNT. '
Path of Varchar2 (500) All_Units_Flag "TRANSACTION_DET/ALL_UNITS_FLAG,"
Path of Varchar2 (500) Entity_Id ' TRANSACTION_DET/ENTITY_ID. "
Path of Varchar2 (500) ENTITY_BRANCH_ID "TRANSACTION_DET/ENTITY_BRANCH_ID,"
Path of Varchar2 (500) "TRANSACTION_DET/RENTAL.
) X
(1 = 1)
the left join XMLTABLE ('/ CT_SYS_STRUCT/FILE_ROWS/FILE_ROW ')
PASSAGE T.FILECONTENT
columns
CAN varchar2 (500) PATH ' INVESTOR_ID_DET / CAN'.
INSTALLMENT_AMOUNT varchar2 (500) PATH "TRANSACTION_DET/INSTALLMENT_AMOUNT".
) Q
(1 = 1)
Where
TRUNC ((TO_DATE (T.RETRIVED_DATE, 'DD-MON-RRRR HH PM'))) = TRUNC(SYSDATE-2)
Order By X.Can Asc, Rownum;
O/P: real
15114LBA01 1000.00 (null) (null) (null) (null) (null) (null) (null)
(null) (null) 15114LBA01 SMF AC UGM 40715117000 15114010001 1511401000102
O/P: expected
amount can_st peut amc command user trxn_no group_ord ind_txn_no
1000.00 15114LBA01 15114LBA01 SMF CA 40715117000 15114010001 1511401000102 UGM It would have been helpful if you had your more detailed condition described in brief.
For as far as I understand nothing xmldata in every line of MFU_FTP_XML_FILES can you wheter structure COMM_TXN_STRUCT or CT_SYS_STRUCT.
So what about something like below
Select
x.*
, q.*
sysdate
de)
Select
x.cols
MFU_FTP_XML_FILES t
, Xmltable ('/ COMM_TXN_STRUCT/FILE_ROWS/FILE_ROW ')
By the way T.Filecontent
Columns
the_x_cols
) x
Where
TRUNC ((TO_DATE (T.RETRIVED_DATE, 'DD-MON-RRRR HH PM'))) = TRUNC(SYSDATE-2)
) x
Join
-a full outer join if there are cans without match
(
Select
q.cols
MFU_FTP_XML_FILES t
, XMLTABLE ('/ CT_SYS_STRUCT/FILE_ROWS/FILE_ROW ')
PASSAGE T.FILECONTENT
columns
CAN varchar2 (500) PATH ' INVESTOR_ID_DET / CAN'.
INSTALLMENT_AMOUNT varchar2 (500) PATH "TRANSACTION_DET/INSTALLMENT_AMOUNT".
) q
Where
TRUNC ((TO_DATE (T.RETRIVED_DATE, 'DD-MON-RRRR HH PM'))) = TRUNC(SYSDATE-2)
) Q
on (x.can = q)
Order By X.Can Asc, Rownum;
-
Hello
We are working on a data warehousing project and wonder how do to join several tables that each are versioned separately (type SCD 2 with a valid and valid to date).
Because for example, we get our client from a single source of information (id customer, name, etc.) and the information on the rate of customer from another source. The sources are different, we have the separate tables for them and each of them gets versioned independently.
Here's my customer table (with its own valid and valuable to the columns).
ID Name of the customer Valid from Valid until the 1 CitiBank 1 JANUARY 14 JANUARY 1, 15 1 New CitiBank 2 JANUARY 15 FEBRUARY 1, 15 1 Latest CitiBank 2 FEBRUARY 15 APRIL 1, 15 And similarly the Client side ID and rating information.
ID Note Valid from Valid until the 1 Platinum 1 JANUARY 14 FEBRUARY 1, 14 1 Premium FEBRUARY 1, 14 1ST MARCH 15 I want to merge the two tables above and present information at a glance. I have some difficulty to determine validates the valid columns.
ID Name of the customer Note Valid from (Calculated) Valid until the (calculated) 1 CitiBank Platinum 1 JANUARY 14 FEBRUARY 1, 14 1 CitiBank Premium FEBRUARY 1, 14 JANUARY 1, 15 1 New CitiBank Premium 2 JANUARY 15 FEBRUARY 1, 15 1 Latest CitiBank Premium 2 FEBRUARY 15 1ST MARCH 15 And it's the query I used to get the above result:
SELECT client. id ,
customer . name ,
CRM . level ,
Greatest (client. vld_fm , crm. vld_fm ),
Least (client. vld_to , crm. vld_to )
DE client client,
client_rating crm
OÙ client. id = crm. id
AND ( client. vld_fm <= crm. vld_fm
AND client. vld_fm <= crm. vld_to
AND client. vld_fm >= crm. vld_fm
AND client. vld_fm >= crm. vld_to )
OR ( client. vld_fm BETWEEN crm. vld_fm AND crm. vld_to )
OR ( client. vld_to BETWEEN crm. vld_fm AND crm. vld_to );
The problem is we have several data sources (and each with its own versions) and joins become so very very complex. Is there a better way to write the query?Or maybe a better way to design our tables?
Thanks for your help.
Anand
Hello
you only need ranges that overlap to join.
Re: How do to sql query in a loop
Is a simpler way to test if the x_start to x_stop range comes into conflict with the range of y_start to y_stop
WHERE x_start <= y_stop AND y_start <= x_stop
In other words, two overlapping if and only if everyone will start before the other ends one. If this is not obvious (and it was certainly not clear to me when I heard it), then look at it this way: two ranges are not overlapping if and only if one of them starts after the end of the other.
Concerning
Marcus
-
JOIN the question... Join two tables without omitting lines
I came across a problem that should be an easy fix (I hope), but I'm having a hard time to come up with a solution.
Basically I have two tables, one with the actual amounts with the budget. I have to write a sql statement select that joins these tables together and includes all of their lines. I was able to join the tables by using JOIN, LEFT JOIN and RIGHT JOIN, but it always fails the lines I need.
Below, I have examples of my tables (AMOUNT_TABLE and BUDGET_TABLE). For simplicity, I built the examples to show the same values in the first four columns, with the 5th and 6th columns (SUB_ACCOUNT, AMOUNT, BUDGET) as the only values that are different. My actual tables are not quite that simple, but I don't think it was relavent to this issue.
AMOUNT_TABLE
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT 2013
1 11111 555555 0000 100 2013 1 11111 555555 1000 100 2013 1 11111 555555 2000 100 2013 1 11111 555555 3000 100 2013 1 11111 555555 4000 100 BUDGET_TABLE
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT BUDGET 2013
1 11111 555555 3000 200 2013 1 11111 555555 4000 200 2013 1 11111 555555 5000 200 2013 1 11111 555555 6000 200 Here's what I hope. Note that SUB_ACCOUNTs 0000, 1000, and 2000 show without budget amounts since there is not a corresponding line in the BUDGET_TABLE. And same for SUB_ACCOUNTs 5000 and 6000, they show budgets with no amount because there is not a corresponding line in the AMOUNT_TABLE.
(exit)
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET 2013 1 11111 555555 0000 100 0 2013 1 11111 555555 1000 100 0 2013 1 11111 555555 2000 100 0 2013 1 11111 555555 3000 100 200 2013 1 11111 555555 4000 100 200 2013 1 11111 555555 5000 0 200 2013 1 11111 555555 6000 0 200 If all goes well, my question is clear. Any help on this would be greatly appreciated. Thanks in advance.
Use the join ANSI - FULL OUTER JOIN syntax:
with amount_table like)
Select fiscal_year 2013, 1 period, 11111 acct_unit, 555555, 0000 sub_account, amount 100 of all the double union
Select 2013,1,11111,555555,1000,100 from all the double union
Select 2013,1,11111,555555,2000,100 from all the double union
Select 2013,1,11111,555555,3000,100 from all the double union
Select double 2013,1,11111,555555,4000,100
),
budget_table like)
Select 1 time, 11111 acct_unit, account 555555, sub_account 3000, 2013 fiscal_year, budget of 200 Union double all the
Select 2013,1,11111,555555,4000,200 from all the double union
Select 2013,1,11111,555555,5000,200 from all the double union
Select double 2013,1,11111,555555,6000,200
)
Select nvl (a.fiscal_year, b.fiscal_year) fiscal_year,
period of NVL (a.period, b.period),
NVL (a.acct_unit, b.acct_unit) acct_unit.
account of NVL (a.Account, b.Account),
NVL (a.sub_account, b.sub_account) sub_account.
Amount NVL(a.amount,0),
NVL(b.budget,0) budget
of amount_table one
full join
budget_table b
on)
a.Fiscal_Year = b.fiscal_year
and
a.period = b.period
and
a.acct_unit = b.acct_unit
and
a.Account = b.account
and
a.sub_account = b.sub_account
)
/
FISCAL_YEAR PERIOD ACCT_UNIT ACCOUNT SUB_ACCOUNT AMOUNT BUDGET
----------- ---------- ---------- ---------- ----------- ---------- ----------
2013 1 11111 555555 0 100 0
2013 1 11111 555555 1000 100 0
2013 1 11111 555555 2000 100 0
2013 1 11111 555555 3000 100 200
2013 1 11111 555555 4000 100 200
2013 1 11111 555555 6000 0 200
2013 1 11111 555555 5000 0 2007 selected lines.
SQL >
SY.
-
Change of shape joining multi tables SQL...
I need to be able to join the tables in the detail section of my master-detail form. Since I have more than three paintings to join, I think that APEX needs to use "ROWID" to track the value of the key of the primary table. When I try substitute basic sql generated for the report to my own joined table I get an error return "IMPOSSIBLE of ANALYSER. If I remove "ROWID" in the statement, then fine. Here's the statement from the apex generated:
Select
"ROWID",.
"PO_ID."
"PO_DET_ID,"
"CHANGE_ORDER,"
'START_DATE ',.
'END_DATE ',.
"PO_DET_AMT,"
"SCOPE."
"PO_STATUS,"
"MRS."
of ' #OWNER # '. " PO_DETAILS ".
where "PO_ID" =: P240_PO_ID
However, I need for the statement as follows:
Select "ROWID",.
po_details.po_id,
po_details.po_det_id,
po_details.change_order,
po_details.start_date,
po_details.end_date,
po_details.po_det_amt,
po_details. Scope,
po_details.po_status,
po_details. WBS
of PO_DETAILS, IN., WBS, PROJECT
where po_details.po_id = po.po_id
and po.po_number = wbs.po_number_id
and po_details.wbs = wbs.wbs_number_id
and substr (wbs.wbs_number_id, 1, 6) = project.wbs_sequence
and project.project_number = nvl(:F101_FPC_NUMBER,project.project_number)
and po_details.po_id =: P240_PO_ID
Then, I get the following ORACLE error:
•Query cannot be parsed in the generator. If you believe that your query is syntactically correct, check the generic "columns" box below the source of the region without analysis. ORA-00918: column ambiguously defined
I'm guessing that the column "defined ambiguous ' is ROWID.
SELECT the query aspect works fine if I remove ROWID, but I then cannot update the table when the user needs to change the data. I get an exception defined by the user.
I am new to APEX, so I do not know there are certain aspects that I'm missing.
Any tips?There is no way to use a join of multiple tables in the APEX?
Of course you can. Have you tried again (with the help of PO_DETAILS ROWID in the select statement)?
I tried with a form on EMP and then modified the query to:
select e."ROWID", e."EMPNO", e."ENAME", e."JOB" from "#OWNER#"."EMP" e, dept d where e.deptno = d.deptno and d.deptno = :P14_DEPTNO
IMHO, it's simply more transparent if you use a view as the source. You select a view, and you update the same point of view.
Published by: InoL on May 14, 2013 13:49
-
date max with multiple joins of tables
Looking for expert advice on the use of max (date) with multiple joins of tables. Several people have tried (and failed) - HELP Please!
The goal is to retrieve the most current joined line of NBRJOBS_EFFECTIVE_DATE for each unique NBRJOBS_PIDM. There are several lines by PIDM with various EFFECTIVE_DATEs. The following SQL returns about 1/3 of the files and there are also some multiples.
The keys are PIDM, POSN and suff
Select NBRJOBS. NBRJOBS.*,
NBRBJOB. NBRBJOB.*
of POSNCTL. Inner join of NBRBJOB NBRBJOB POSNCTL. NBRJOBS NBRJOBS on (NBRBJOB. NBRBJOB_PIDM = NBRJOBS. NBRJOBS_PIDM) and (NBRBJOB. NBRBJOB_POSN = NBRJOBS. NBRJOBS_POSN) and (NBRBJOB. NBRBJOB_SUFF = NBRJOBS. NBRJOBS_SUFF)
where NBRJOBS. NBRJOBS_SUFF <>'LS '.
and NBRBJOB. NBRBJOB_CONTRACT_TYPE = 'P '.
and NBRJOBS. NBRJOBS_EFFECTIVE_DATE =
(select Max (NBRJOBS1. NBRJOBS_EFFECTIVE_DATE) as 'EffectDate '.
of POSNCTL. NBRJOBS NBRJOBS1
where NBRJOBS1. NBRJOBS_PIDM = NBRJOBS. NBRJOBS_PIDM
and NBRJOBS1. NBRJOBS_POSN = NBRJOBS. NBRJOBS_POSN
and NBRJOBS1. NBRJOBS_SUFF = NBRJOBS. NBRJOBS_SUFF
and NBRJOBS1. NBRJOBS_SUFF <>'LS '.
and NBRJOBS1. NBRJOBS_EFFECTIVE_DATE < = to_date('2011/11/15','yy/mm/dd'))
order of NBRJOBS. NBRJOBS_PIDMWelcome to the forum!
We don't know what you are trying to do.
You want all of the columns in the rows where NBRJOBS_EFFECTIVE_DATE is the date limit before a given date (November 15, 2011 in this example) for all rows in the result set with this NBRJOBS_PIDM? If so, here is one way:with GOT_R_NUM as ( select NBRJOBS.NBRJOBS.*, NBRBJOB.NBRBJOB.* -- You may have to give aliases, so that every column has a unique name , rank () over ( partition by NBRJOBS.NBRJOBS_PIDM order by NBRJOBS.NBRJOBS_EFFECTIVE_DATE desc ) as R_NUM from POSNCTL.NBRBJOB NBRBJOB inner join POSNCTL.NBRJOBS NBRJOBS on (NBRBJOB.NBRBJOB_PIDM = NBRJOBS.NBRJOBS_PIDM) and (NBRBJOB.NBRBJOB_POSN = NBRJOBS.NBRJOBS_POSN) and (NBRBJOB.NBRBJOB_SUFF = NBRJOBS.NBRJOBS_SUFF) where NBRJOBS.NBRJOBS_SUFF != 'LS' -- Is this what you meant? and NBRBJOB.NBRBJOB_CONTRACT_TYPE ='P' and NBRJOBS.NBRJOBS_EFFECTIVE_DATE <= to_date ('2011/11/15', 'yyyy/mm/dd') ) select * -- Or list all columns except R_NUM from GOT_R_NUM where R_NUM = 1 order by NBRJOBS_PIDM ;
Normally this site does not display the <>inequality operator; He thinks it's some kind of beacon.
Whenever you post on this site, use the other inequality operator (equivalent), *! = *.I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) for all the tables involved and the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
You will get better results faster if you always include this information whenever you have a problem. -
BAD RESULTS WITH OUTER JOINS AND TABLES WITH A CHECK CONSTRAINT
HII All,
Could any such a me when we encounter this bug? Please help me with a simple example so that I can search for them in my PB.
Bug:-8447623
Bug / / Desc: BAD RESULTS WITH OUTER JOINS AND TABLES WITH a CHECK CONSTRAINT
I ran the outer joins with check queries constraint 11G 11.1.0.7.0 and 10 g 2, but the result is the same. Need to know the scenario where I will face this bug of your experts and people who have already experienced this bug.
Version: -.
SQL> select * from v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production PL/SQL Release 11.1.0.7.0 - Production CORE 11.1.0.7.0 Production TNS for Solaris: Version 11.1.0.7.0 - Production NLSRTL Version 11.1.0.7.0 - Production
Why do you not use the description of the bug test case in Metalink (we obviously can't post it here because it would violate the copyright of Metalink)? Your test case is not a candidate for the elimination of the join, so he did not have the bug.
Have you really read the description of the bug in Metalink rather than just looking at the title of the bug? The bug itself is quite clear that a query plan that involves the elimination of the join is a necessary condition. The title of bug nothing will never tell the whole story.
If you try to work through a few tens of thousands of bugs in 11.1.0.7, of which many are not published, trying to determine whether your application would be affected by the bug? Wouldn't be order of magnitude easier to upgrade the application to 11.1.0.7 in a test environment and test the application to see what, if anything, breaks? Understand that the vast majority of the problems that people experience during an upgrade are not the result of bugs - they are the result of changes in behaviour documented as changes in query plans. And among those who encounter bugs, a relatively large fraction of the new variety. Even if you have completed the Herculean task of verifying each bug on your code base, which would not significantly easier upgrade. In addition, at the time wherever you actually performed this analysis, Oracle reportedly released 3 or 4 new versions.
And at this stage would be unwise to consider an upgrade to 11.2?
Justin
-
How to join the table in screens LCD
Hello
How can I join the tables in the screens LCD and show them in a datagrid?
I run LCDS3 and tomcat.
Any help is appricitated
User (name, surname, address)
Address (address, State, country, postal code)
If you want to display data below in your data grid
---------------------------------------------------------------------------
firstName. lastName. State
---------------------------------------------------------------------------
user.firstName | user.lastName | User.Address.State
-
Update statement with joins of tables and where Clause
Hi, I have MS SQL background and I try to execute an update statement in Oracle with joins of tables. However, the syntax below does not work but I think it works for MS SQL.
Basically, the base table must be attached to a master table trend with monthly snapshots, an account will be only an entry for a given date monthly. Where clause must be limited to accounts within a certain range of interest rates.
The first approach returns command SQL ORA-00933 not correctly completed, and the second approach returns ORA-01427 row below query returns multiple rows. Can anyone help? Thanks in advance!
1:
Update PenaltyAll
Set a.indicator = month (b.)
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
where a.monthend='01/31/2009' and b.date='12/31/2008' and b.apr < 20
2:
Update PenaltyAll
adjustment indicator =
(select to_char (b., 'MM')
of PenaltyAll an inner join Master b on a.acctno = b.accountnumber
"where to_char (a.monthend,'mm/dd/yyyy ') = 31 January 2009"
(et to_char(b.date,'mm/dd/yyyy') = December 31, 2008 "
and b.apr < 20)
Published by: sqlrookie on August 21, 2009 07:04I edited my post, that was my mistake, ANC you try now?
-
Hello
My doubt is that I can join the table with view in the sub clause where condition in the query. If so, the query below will take 4 hrs to run it. I can do the below query to write under the simpler name?
SELECT *
uavlsum - view
FROM uabpymt p, uavlsum l
WHERE uabpymt_appl_ind = 'N'
AND uabpymt_amount > 5
AND l.uavlsum_balance < 0
AND l.uavlsum_cust_code = p.uabpymt_cust_code
AND l.uavlsum_prem_code = p.uabpymt_prem_code
uabpymt - table
The script view below:
CREATE OR REPLACE VIEW UAVLSUM
(UAVLSUM_CUST_CODE, UAVLSUM_PREM_CODE, UAVLSUM_AMOUNT, UAVLSUM_BALANCE)
AS
SELECT cust_code,
prem_code,
SUM(amount),
SUM(balance)
FROM (
SELECT uabopen_cust_code cust_code,
uabopen_prem_code prem_code,
uabopen_billed_chg amount,
uabopen_balance balance
FROM uimsmgr.uabopen
UNION ALL
SELECT uabpymt_cust_code,
uabpymt_prem_code,
uabpymt_amount * -1,
uabpymt_balance * -1
FROM uimsmgr.uabpymt
UNION ALL
SELECT uabadje_cust_code,
uabadje_prem_code,
uabadje_balance,
to_number(0)
FROM uimsmgr.uabadje
WHERE uabadje_balance <> 0)
GROUP BY cust_code,
prem_codesamuraibala wrote:
Find the below out of the plan to explain that we get from the execution of the queryYou use the RULE-based optimizer. What version of Oracle (4-digit, e.g. 9.2.0.8) are you using?
The execution plan essentially uses the UNION ALL like table to get the corresponding lines of UABPYMT via an index seek according to join at the wheel. According to the number of rows returned by the UNION ALL and grouping factor / selectivity of the index, this could be quite ineffective.
In addition the GROUP BY operation obviously was merged in the main query, so a NO_MERGE hint could help reduce the number of rows from the source line of conduct UNION ALL:
SELECT /*+ NO_MERGE (l) */ * FROM uabpymt p, uavlsum l ...
With the help of the COST based optimizer might give better results.
Kind regards
RandolfOracle related blog stuff:
http://Oracle-Randolf.blogspot.com/SQLTools ++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676 /.
http://sourceforge.NET/projects/SQLT-pp/ -
Join the tables in the responses
I would like to know if it is possible to join the tables together as below in the answers?
Select a.Field1, b.Field1
FROM tableA an outer join left tableA b on
a.Field1 = b.FieldIf you want to make an INNER JOIN, and then type INNER JOIN instead of LEFT INNER JOIN.
If you want to left outer join and LEFT OUTER JOIN instead of INTERNAL LEFT JOIN type.
Nothing asked as a left inner join. That is why it gives error + [nQSError: 27002] near
+. Thank you
-
Outer Join and joining several Tables
Hello
Oracle Database 10 g Express Edition Release 10.2.0.1.0 - product
I have three tables AddProject, AssociateProjectLead, AddAssociate. Now I'm generating a report who will join AddProject and AssociateProjectLead for a list of all the projects, even if it doenst have a project coordinator. I used the outer join for this. However, if I want the name of the project leader, I need to search for AddAssociate table. By joining this table also, the outer join is no longer valid. Please see the result below
How can I select all the values in table AddProject?CREATE TABLE "ADDPROJECT" ( "VERSIONNO" NUMBER(*,0), "PROJID" VARCHAR2(20), "PROJNAME" VARCHAR2(60), "PROJSTARTDATE" DATE, "PROJSTATUS" VARCHAR2(20), "PROJENDDATE" DATE, "PROJENDTYPE" VARCHAR2(20), "PROJENDREASON" VARCHAR2(1000), "UCPROJECTMANAGER" VARCHAR2(20), "FROMDATE" DATE, "TODATE" DATE, "SRCHFIELD" VARCHAR2(20), "OPERATOR" VARCHAR2(20), "PARENTPROJID" VARCHAR2(20), "PROJHIDDENDATE" VARCHAR2(20), CONSTRAINT "PK_B36" PRIMARY KEY ("PROJID", "PROJHIDDENDATE") ENABLE ) CREATE TABLE "ADDASSOCIATE" ( "VERSIONNO" NUMBER(*,0), "ASSOCIATEID" NUMBER(9,0) NOT NULL ENABLE, "ASSOCIATENAME" VARCHAR2(100) NOT NULL ENABLE, "CTOJOINDATE" DATE, "STATUS" VARCHAR2(20), "ENDDATE" DATE, "SRCHFIELD" VARCHAR2(20), "OPERATOR" VARCHAR2(20), "FROMDATE" DATE, "TODATE" DATE, CONSTRAINT "PK_B23" PRIMARY KEY ("ASSOCIATEID") ENABLE ) CREATE TABLE "ASSOCIATEPROJECTLEAD" ( "VERSIONNO" NUMBER(*,0), "PROJLEADASSOID" NUMBER(9,0), "PROJID" VARCHAR2(20), "ASSOCIATEID" NUMBER(9,0), "PROJLEADSTARTDATE" DATE, "STATUS" VARCHAR2(20), "ASSOCPROJHIDDENDATE" VARCHAR2(20), "PROJHIDDENDATE" VARCHAR2(20), "ENDDATE" DATE, CONSTRAINT "PK_B40" PRIMARY KEY ("ASSOCIATEID", "PROJID", "ASSOCPROJHIDDENDATE") ENABLE ) elect ap.projid,apl.associateid from addproject ap, associateprojectlead apl where ap.projid = apl.projid(+) and ap.projhiddendate = apl.projhiddendate(+) PROJID ASSOCIATEID Proj08 75825 Proj09 75825 Proj10 75825 Proj11 75825 Proj12 259811 Proj01 103035 Proj02 103035 Proj03 320092 Proj04 320092 Proj05 120974 Proj06 367393 Proj07 117618 Proj07 224882 Proj07 246652 prj001 - prj001 - 16 rows returned in 0.00 seconds select ap.projid,apl.associateid,aa.associatename from addproject ap, associateprojectlead apl,addassociate aa where ap.projid = apl.projid(+) and ap.projhiddendate = apl.projhiddendate(+) and apl.associateid = aa.associateid PROJID ASSOCIATEID ASSOCIATENAME Proj11 75825 Amarendra Kumar Singh Proj10 75825 Amarendra Kumar Singh Proj09 75825 Amarendra Kumar Singh Proj08 75825 Amarendra Kumar Singh Proj02 103035 Rajesh Jayaprakash Proj01 103035 Rajesh Jayaprakash Proj07 117618 Chetan Malhotra Proj05 120974 Perumal Rajaram Proj07 224882 Dilshad Ahmad Proj07 246652 Shankar Kausley Proj12 259811 Arunchandar Arun Vasan Proj04 320092 Venkatesh Sarangan Proj03 320092 Venkatesh Sarangan Proj06 367393 Venkata Ramakrishna P 14 rows returned in 0.00 seconds
Published by: Pramukh on August 23, 2012 12:18Hello
I could get the result with a bit of modification
select ap.projid, apl.associateid, aa.associatename from addproject ap left outer join associateprojectlead apl on ap.projid = apl.projid and ap.projhiddendate = apl.projhiddendate left outer join addassociate aa on apl.associateid = aa.associateid
As a follow-up, I have a request more. In the report form, the user can select a particular project ID and the report should be generated as a result. For example;-he wants to see the results of the only "Proj08". I get the output as below, while the result should display only the details of 'Proj08 '.
select ap.projid, apl.associateid, aa.associatename from addproject ap left outer join associateprojectlead apl on ap.projid = apl.projid and ap.projhiddendate = apl.projhiddendate and ap.projID = 'Proj08' left outer join addassociate aa on apl.associateid = aa.associateid ORDER BY ap.projID PROJID ASSOCIATEID ASSOCIATENAME Proj01 - - Proj02 - - Proj03 - - Proj04 - - Proj05 - - Proj06 - - Proj07 - - Proj08 75825 Amarendra Kumar Singh Proj09 - - Proj10 - - Proj11 - - Proj12 - - prj001 - - prj001 - -
-
Please see the attached link for table structures and data of the sample.
There will be several lines in the table of SALES with different SALETYPEs. There may be several lines in the table RETURNS, corresponding to some of the points of SALE. RETURNS the table has a foreign key to the SALE. The report that I am trying to generate with a select sql statement must include a line for each type of sale (from table SALETYPE) and the sum of sale amounts corresponding to this type of sale of the SALES table. The table may not return the entries for all types of sales and the amount of Scripture must be reported as zero. The SQL I use is below, but does not work. I hope that I have explained this correctly. Please see the doc attached for typical data that I work with. Can someone please?
https://spreadsheets.Google.com/pub?key=0AnDmnUJXOChwdGF2ZjdjdHFtMGF1MkJ3MWtjQ2JfUmc & hl = in & Single = true & gid = 0 & output = html
Select SUM (s.amount) as sum_amount, t.sale_type from SALES s, SALETYPE t, r RETURNS
where s.id = r.id
and s.sale_type_id = t.id
T.sale_type group;
Published by: 801941 on October 12, 2010 15:02Hello - the second displays almost had. what you want to do is joining several tables at once - impossible with the syntax of the oracle, but possible if you use ANSI SQL.
Wrote file afiedt.buf 1 WITH s AS 2 (SELECT 1 id, 1 sale_type_id, 10 amount FROM dual 3 UNION ALL 4 SELECT 2, 1, 10 FROM dual 5 UNION ALL 6 SELECT 3, 2, 10 FROM dual 7 UNION ALL 8 SELECT 4, 2, 10 FROM dual 9 UNION ALL 10 SELECT 5, 3, 10 FROM dual 11 UNION ALL 12 SELECT 6, 4, 10 FROM dual), 13 r AS 14 (SELECT 2 sale_id FROM dual 15 UNION ALL 16 SELECT 3 FROM dual 17 UNION ALL 18 SELECT 4 FROM dual), 19 t AS 20 (SELECT 1 sale_type_id, 100 sale_type FROM dual 21 UNION ALL 22 SELECT 2, 200 FROM dual 23 UNION ALL 24 SELECT 3, 300 FROM dual 25 UNION ALL 26 SELECT 4, 400 FROM dual) 27 SELECT nvl(SUM(s.amount),0) total_amount, t.sale_type 28 FROM t 29 join r on (1=1) 30 left outer join s on (s.id = r.sale_id and s.sale_type_id = t.sale_type_id) 31 --WHERE s.id(+) = r.sale_id 32 -- AND s.sale_type_id(+) = t.sale_type_id 33 GROUP BY t.sale_type 34* order by t.sale_type SQL> / TOTAL_AMOUNT SALE_TYPE ------------ ---------- 10 100 20 200 0 300 0 400 4 rows selected.
The two commented lines are what you are trying to achieve using the syntax of the oracle, but which will give you an error.
-
Hello
My 1st question
My 2nd questionSometimes i have hard time in deciding the weather to use equi join or left join or right join ?? After looking at the data model i can understand how the tables can be joined on what attribute but i lack in making decision weather to use left join or right join for one to many or many to one relationships I know the concept of right join and left join but i get confused in what scenario i need to use left join or right join and what join to use for one to many relationships or many to one relationships If you have any techniques or suggetions how to use them that will be great!!
___Table1___ TableA
| | | |
Table2, table3 table 4 < - TableC - TableB-|
Table 1 a 1 of many relationships of table2, table 3, table 4
I, e Table1-> table 2, table 3, table 4
Table A has many relationships in table 1 B, i, e TableA-> table B
Table B has 1 in-several in Table C, i, e table B-> table C
Table C has many relationships in table 4, i, e 1 C table-> table 4
I know the attributes to use to join these tables, but my question is what join what I use left join or right join or Equi join (I don't think I can use this)
Something like that in my SQL query in where clause (I don't know if this is right).
Where
Table1. ID = table2. ID
or table1.my_field = table3.id
or table1.my_field = table4.id
or tableA. ID = tableB.id---(ce que je dois opérateur OR ou opérateur AND???)
or tableB.id = TableC.id
or tablec.id = table4.id
I don't know if this right or do I have to use the left join on right join or and or operator operator 'OR' is something I m really confued subject.
Any advice greatly appriciated thank you!
Published by: user642297 on May 12, 2010 09:49
Published by: user642297 on May 12, 2010 09:51Apart from referring to various documents and examples...
Use the following examples as 'Playground' and experience to get an idea of the various "joins".-- SETUP for examples... drop table A; drop table B; drop table C; create table a (ca int, sa varchar2(50)); create table b (cb int, sb varchar2(50)); create table c (cc int, sc varchar2(50)); insert into A select * from ( select level myid, to_char( to_date( level,'J'),'Jsp') mystr from dual connect by level < 11 ); commit; insert into B select * from ( select level myid, to_char( to_date( level,'J'),'Jsp') mystr from dual connect by level < 21 ) where mod(myid,2) = 0; commit; insert into C select * from ( select level myid, to_char( to_date( level,'J'),'Jsp') mystr from dual connect by level < 11 ) where myid < 6; commit; -- Verify the setup select * from A; select * from B; select * from C; -- ************************************************************** -- Requirement EQUI JOIN 1. (AKA INNER JOIN) -- To select rows from A and MATCHING rows from B -- use A JOIN B or B JOIN A -- -- ANSI SQL syntax select * from A JOIN B on (A.CA = B.CB) ; -- **** OR **** select * from B JOIN A on (A.CA = B.CB) ; -- OR Traditional Oracle syntax select * from A, B where A.CA = B.CB ; -- ************************************************************** -- Requirement EQUI JOIN 2. (AKA INNER JOIN) -- To select rows from A and MATCHING rows from B and matching -- rows from C -- use A JOIN B JOIN C -- -- ANSI SQL syntax select * from A JOIN B on (A.CA = B.CB) JOIN C on(B.CB = C.CC) ; -- OR Traditional Oracle syntax select * from A, B, C where A.CA = B.CB and B.CB = C.CC ; -- ************************************************************** -- Requirement OUTER JOIN 1. -- To select ALL rows from A and ONLY MATCHING rows from B -- use A LEFT OUTER JOIN B or B RIGHT OUTER JOIN A -- -- The columns for table B will have NULL value where a -- match for A is not found -- -- ANSI SQL syntax select * from A LEFT OUTER JOIN B on (A.CA = B.CB) ; -- **** OR **** select * from B RIGHT OUTER JOIN A on (A.CA = B.CB) ; -- OR Traditional Oracle syntax select * from A, B where A.CA = B.CB(+) ; ---------------------------------------------------------- -- The queries above are EQUIVALENT - return the same -- result set. -- **** However note the "order" in which the rows are -- returned by default. ---------------------------------------------------------- -- ************************************************************** -- Requirement OUTER JOIN 2. -- To select ALL rows from B and ONLY MATCHING rows from A -- use B LEFT OUTER JOIN A or A RIGHT OUTER JOIN B -- -- The columns for table A will have NULL value where a -- match for B is not found -- -- ANSI SQL syntax select * from B LEFT OUTER JOIN A on (A.CA = B.CB) ; -- **** OR **** select * from A RIGHT OUTER JOIN B on (A.CA = B.CB) ; -- Traditional Oracle syntax select * from A, B where A.CA(+) = B.CB ; -- ************************************************************** -- Requirement OUTER JOIN 3. -- To select ALL rows from A and ONLY MATCHING rows from B -- AND select those rows from C that match rows from B -- -- ANSI SQL syntax select * from A LEFT OUTER JOIN B on (A.CA = B.CB) LEFT OUTER JOIN C on (B.CB = C.CC) ; -- OR Traditional Oracle syntax select * from A, B, C where A.CA = B.CB(+) and B.CB = C.CC(+) ; ---------------------------------------------------------- -- and So on... -- ************************************************************** -- Requirement FULL JOIN 3. -- To select ALL rows from A and ALL rows from B -- AND MATCH the rows from A and B that match, but return even -- the unmatching rows. -- -- ANSI SQL syntax select * from A FULL OUTER JOIN B on (A.CA = B.CB) ; -- OR Traditional Oracle syntax -- There is no equivalent for FULL OUTER join in traditional -- syntax. (Though it can be achieved using other means) -----------------------------------------------------------------
VR,
Sudhakar B. -
I have a MySQL table that contains two user, each a different user id. I want to make a query that joins the table containing the table user to retrieve user names corresponding to these two user id how is this possible?
"AngryCloud" wrote in message
News:fgg691$1JT$1@forums. Macromedia.com...
> Sorry, I do not think that my question I explained that well. Let me rephrase:
>
> I have a MySQL table that contains two user id, each other
> user.
> Each of the id is in another column. I want to make a query that
> joins
> user table that contains the table to retrieve the corresponding user names to the
> time
> user
>
> Lets say I have a table called Messages. A record in the salons of tables the
> ID recipient is 26 'and the sender ID is 14'. I want to create a query
> who
> joins the table of Messages containing the data of the user table to get the names of users of
> each
> these users.
>
> Just for possible yet understand, let me show you an example query
> who
> doesn't make any sense, but it might be useful to describe what I'm trying
> reach.
>
> 'SELECT messages.recipient_id, messages.sender_id, messages.message,
> user_data.username
> MESSAGES
> User_data LEFT JOIN ON messages.recipient_id = user_data.id
' > User_data LEFT JOIN ON messages.sender_id = user_data.id.in fact it makes sense, but you must apply aliases for tables
and columnsSELECT messages.recipient_id, messages.sender_id, messages.message,
recipient_data. UserName as beneficiary, sender_data.username as sender
((MESSAGES
User_data LEFT JOIN AS recipient_data ON messages.recipient_id =
USER_DATA.ID)
User_data LEFT JOIN AS sender_data ON messages.sender_id = user_data.id)
Maybe you are looking for
-
Opening of the problem of downloaded files
I have already asked for help with this problem and received several suggestions that did not work. I now have more information that could be a clue. I have the same version (34.0.5) on my win8 pc and it works fine. Also, I recently restored mty win7
-
iMovie does not open Costco DVD VHS movies converted
iMovie for Mac does not open Costco DVD converts VHS movies at home. I don't know that I was able to do what a few years with an older version of iMovie. There is a limitation with iMovie? DVD of Costco is just a bunch of old family VHS home movies.
-
HP Envy: Battery check failed
Battery plugged in but not supported. Has conducted an audit of the system and received the following information: Battery check: primary - replace (42) Failure ID: U4MN7R-67H88N-XD7X1F-C0C403 Product ID: C6N88UA #ABA Main battery Help, please. I jus
-
exe application 0xc000007b application error failed to initialize properly on startup.
Original title: exe application 0xc000007b error Hello When I start my computer, I receive. (exe application error the application failed to initialize properly 0xc000007b) Thank you James
-
Smartphones Newby blackBerry for I hour and software
I just got it and he is in charge. Unlike most of the other there is no details except for the flashing green light. He will tell when it is fully charged? I'm about to install the Manager (version 6.7.3 - 2010th for windows 2000/xp/Vista 32/64 bit).