Joining MySQL Tables
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?
in fact it makes sense, but you must apply aliases for tables SELECT messages.recipient_id, messages.sender_id, messages.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.
and columns
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)
Tags: Dreamweaver
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.
-
Accuracy of counties line in the MySQL Table
I was just looking at the counts of row of the table for some of my MySQL tables listed in HQ... some of these tables should only increase in number of lines (never delete us rows), but table varies greatly as to how many lines is in the table.
So I have two questions...
(1) these figures are absolutely not accurate... his watch a table which always increases in length as having 100 lines, then 75 and 90 and 88, etc.. IT should show 100, 101, 104, 110.
(2) I know that the MySQL "SELECT COUNT (*) FROM tablename" statement is VERY slow on my servers. HQ runs this command on my database? If so, I need to disable this "feature" because he's going to kill my database. The COUNT command on a table over 1 million lines takes an incredible amount of resources on my MySQL server... and we try to avoid to execute commands to COUNT on these large tables...
(a) if it executes a SELECT COUNT?
(b) can I turn that off?
Thank you!
StephenHello
It seems to me that hyperic is not a command select count(), but one
display the State of the table. It is incorrect when you use innodb tables..."Some drivers of storage, such as MyISAM tables, store the exact number. For others
engine storage, such as InnoDB, this value is an approximation and may
changing the actual value by as much as 40-50%. In this case, use
SELECT COUNT (*) to get an accurate count. »The advantage of this is that it is not processor intensive.
Rgds
Simon.
>
> I was just looking at the counts of row of the table for some of my MySQL tables
> listed in HQ... some of these tables should only be more and more
> lines (never delete us lines), but the picture varies greatly as to how much
> rows are in the table.
>
> So I have two questions...
> 1) these numbers are absolutely not accurate... its a table showing that
> increasing in length as having 100 lines, then 75, then 90, then 88,.
> etc. IT should show 100, 101, 104, 110.
>
(> 2) I know that the MySQL "SELECT COUNT (*) FROM tablename" statement is
> VERY slow on my servers. HQ runs this command on my database? If
> then I have to disable this "feature" because he's going to kill my database. The
> Order of COUNTY on a table over 1 million lines takes an incredible amount
> resources on my MySQL server... and we try to avoid running COUNT
> orders on these large tables...
(> a) if he executes a SELECT COUNT?
(> b) can I turn that off?
>
> Thank you!
> Stephen
>
> --
> This message has been scanned for viruses and
> dangerous by MailScanner and is content
> supposed to be clean. -
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
-
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 - -
-
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. -
Can I use a username of the php session to select a mysql table?
In my site, I have a situation where
$_SESSION ['MM_Username"]
will be the same name as a MYSQL table prepared.
(There will be a limited number of users and tables)
Instead of writing a long series of "else if" to deal with each user of each page, I want to use the $_SESSION ['MM_Username'] to point to the correct MSQL table.
For example
<? PHP $query_rstPalabs = "SELECT * FROM patricia WHERE YesNo > = 1"; ? >
How can I replace the $_SESSION ['MM_Username'] for 'patricia' here in a way that the SQL would choose the table 'patricia '?
Please be aware that I am not a professional designer and wading in the shallows of PHP/MSQL. I use DW2004MX to help.
Thank you.Smiffy47,
Assign a variable with $_SESSION ['MM_Username"]. Call the variable in your query:
Example:
$user = $_SESSION ['MM_Username"];
$user WHERE yesno >= 1" ; =""?>
Be sure to use session_start at the beginning of your page so that you are allowed to call session variables in your application.
This should be added before your declaration DOCTYPE (the very beginning of your page).
-ST
-
value of radio button shows only not in the mysql table
This looks like a small problem, but I can't seem to find the solution. I created a form on a web page. After the form is completed, a confirmation is sent to the person who filled out the form and a mysql table is populated with the information from the form. Everything works well except for one small thing: the value of the radio button does not appear in the table.
Here is the form: http://www.webdevpractice.com/genoptix/CE/register.php
Here is the table on the Web page: http://www.webdevpractice.com/genoptix/CE/admin/index.php you will see that the Contact Me column does not.
Here insert the php code in the registration form page:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "registration")) { $insertSQL = sprintf("INSERT INTO registrants (registrant_id, first_name, last_name, medtech_id, job_title, company, city, `state`, email, phone, contact) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['registrant_id'], "int"), GetSQLValueString($_POST['first_name'], "text"), GetSQLValueString($_POST['last_name'], "text"), GetSQLValueString($_POST['medtech_id'], "text"), GetSQLValueString($_POST['job_title'], "text"), GetSQLValueString($_POST['company'], "text"), GetSQLValueString($_POST['city'], "text"), GetSQLValueString($_POST['state'], "text"), GetSQLValueString($_POST['email'], "text"), GetSQLValueString($_POST['phone'], "text"), GetSQLValueString(isset($_POST['contact']) ? "true" : "", "defined","'Y'","'N'"));
I used phpMyAdmin to create the db and table. I put the field contact as follows:
Type: ENUM
Length/values: ', 'y '.
Default: no
Ranking: utf8_unicode_ci
Can you find the problem?
I found the problem. I don't broadcast my stupidity, but I have a time I changed the last field of contact_me contact and I forgot to download the change on one of the files (I thought I had downloaded it). In any case, thanks for responding to my message. It is good to know that altruistic GRAMPS remains!
-
How can I show more information summary of a MySQL table
As part of an air show web site, we would like to know where our visitors come from. Then, when people buy tickets ask us what their zip code and also to record the number of adults / children / toddler tickets were sold at the party. The result will be a MySQL table containing the following columns Zip, City/St, adults, children, infants. CitySt will be consulted when the ticket seller between the postal code and stored in the table.
I want to display a sorting table by CitySt with separate columns showing how many adults / children / children below age came from each CitySt, I only want to show the totals by CitySt and no individual sales. I can do the details, but how to create summary information table only by CitySt. Something like that
Header 1 Header 2 Header 3 Header 4 City ST Adults Children Toddler N ° 1 city 12 4 2 City 2 8 10 4 City 3 10 6 0 I can view the individual table rows, but how to display just info summary by city?
Thank you
Tony
You must use the sum aggregate function and the GROUP BY clause.
Select CitySt, sum (Adults), sum (Children), sum (Toddlers) from myTable
CitySt group -
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
-
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.
Maybe you are looking for
-
How do I fix this menu bookmarks
I have a question where my bookmarks menu has about 5 additional separators, which should not be just there, it's a minor problem, but it also annoys the hell out of me at the same time, here is a screenshot of what I mean. [URL =http://imageshack.us
-
No update on the request of Toshiba Bluetooth Stack SDK
Dear all,I placed a request for Toshiba Bluetooth Stack SDK via this link [http://portal.toshiba-tro.de/web/guest/request | http://portal.toshiba-tro.de/web/guest/request] 2-3 weeks back. I have received no response from the team so far. How long it
-
My volume control is missing from the taskbar.
Even if I had the volume control on the taskbar before, I get the message under sound & audio in the control panel volume control has not been installed and that I should go to add/remove program to install. How do I do that?
-
bars Black around like tube video you...
I put cd in last night to play this game I think that he messed up in my video, I get black lines... At each end like youtube. not the full screen...
-
My Sansa Clip died last Friday, and I am wrong because I listen to podcasts during travel or any other 'time' I. The things that I really liked in this regard were: -Deleting a file on the drive -Fast forward or rewind has become progressively more q