Help with listing records from two tables
Hi: I have two tables joined by the first field. The field is primary key in first table. Need help listing records from both tables with each record one line/record.
create table EVENTS (
event_key varchar2(64) primary key,
event_description varchar2(64),
create_time int
create table EVENT_UPDATES (
event_key varchar2(64) NOT NULL ,
update_description varchar2(64),
update_time int
insert into EVENTS values('Event1', 'This is event1', 1);
insert into EVENT_UPDATES values('Event1', 'Ticket created', 3);
insert into EVENT_UPDATES values('Event1', 'Event cleared', 10);
insert into EVENTS values('Event2', 'This is event2', 4);
insert into EVENT_UPDATES values('Event2', 'Ticket created', 6);
insert into EVENT_UPDATES values('Event2', 'Event cleared', 8);I want to print each record in EVENTS table as one line and corresponding records in EVENT_UPDATES as one line/record like this
Event1 1 This is event1
3 Ticket created
10 Event cleared
Event2 4 This is event2
6 Ticket created
8 Event clearedTIA
Ravi
select case weight
when 1 then event_key
end key,
time_val,
description
from (
select event_key,
create_time time_val,
event_description description,
1 weight
from events
union all
select event_key,
update_time,
update_description,
2 weight
from event_updates
order by event_key,
weight
KEY TIME_VAL DESCRIPTION
Event1 1 This is event1
3 Ticket created
10 Event cleared
Event2 4 This is event2
6 Ticket created
8 Event cleared
6 rows selected.
SQL> SY.
Similar Messages
-
How do I extract matching records from two tables?
I'm trying to extract client records from our client database to put together a very targeted email campaign. As an example, the result I want is a list of names and email addresses of those clients who have a record in our system, have not had a visit in our clinic in the last year, and live within 200 miles of our clinic. I can capture the first two criteria in one extract, and the second in another. I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
Can someone tell me if this is possible and if so, how to do it?
I'd be very appreciative of any help, thank you.conejo61 wrote:
I can then import those as tab delimited data into Numbers. What I then need to do is create a third table that represents ONLY those records that exist in both tables.
You can create a column that generates a serial marker on the table from which you want to transfer the data, making all the names that also appear on the other table. Not that the formula will mark only exact matches.
Here's a short example:
Table 1 on the left, is one of the two tables imported from the tab delimited data files. It has other data, but only the names in column A are used to identify records appearing on both tables.
Table 2 on the right, contains the names and other data (represented by the email addresses in column B), to be transferred to the third table.
Column C of this table contains the formula that counts off the rows containing names appearing on both tables. The version below is in C2, and is filled down to the end of the column.
=IF(COUNTIF(Table 1 :: $B,A2)>0,MAX($C$1:C1)+1,"")
Note that jane Doe is not counted (or transferred) as her name is recorded differently on the two tables.
Table 3 is the results table. It contains one formula for each column to be transferred from Table 2 to Table 3.
A2: =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $A))
B2: =IF((ROW()-1>MAX(Table 2 :: $C)),"",LOOKUP(ROW()-1,Table 2 :: $C,Table 2 :: $B))
Regards,
Barry
EDIT: I was working in Numbers '09 when developing this, and got the following warning when I saved a copy as an iWork '08 document:
Referencing row or column ranges that include header or footer cells isn't supported. The formula references were updated to exclude header and footer cells.
The formulas in Table 2::C2 references C1. You may have to ensure that Table 2 does not include a header row.
B.
EDIT2: A check on the file in Numbers '08 showed no apparent change to the formula, and editing Jane Doe's name on table 1 resulted in her name being added to Table 3.
Message was edited by: Barry -
Can i select Records from two tables into an itab.
Hi,
Suppose that i have two tables spfli and sflight.
Now i want the records from both the tables into a single internal table.
If so please let me know how this can be done.
itab should consist of all the columns in sflight and spfli.
Regards,
SaiSai,
Yes u can do it using JOINs.
Use this link for ref
http://www.sap-img.com/abap/inner-joins.htm
INNER JOIN results are an intersection of the tables being joined where in only if both the tables havethe data the result is pused onto the result set.
WHERE as in LEFT OUTR JOIN you can push the data of the LEF T table on the resultset even when the join condition is not met.
The use is that you wantto have all the data that is there in left table and also the right table if the join condition is a success then right table fileds will have data else they are initial.
OUTJOIN's are used in MAINTENANNCE VIEWS, HELP VIEWS .
INNER JOINS are used DATABSE VIEWS.
Inner Join:-
SELECT pcarrid pconnid ffldate bbookid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM ( ( spfli AS p
INNER JOIN sflight AS f ON pcarrid = fcarrid AND
pconnid = fconnid )
INNER JOIN sbook AS b ON bcarrid = fcarrid AND
bconnid = fconnid AND
bfldate = ffldate )
WHERE p~cityfrom = 'FRANKFURT' AND
p~cityto = 'NEW YORK' AND
fseatsmax > fseatsocc.
Left Outer Join
SELECT scarrid scarrname p~connid
INTO CORRESPONDING FIELDS OF TABLE itab
FROM scarr AS s
LEFT OUTER JOIN spfli AS p ON scarrid = pcarrid AND
p~cityfrom = 'FRANKFURT'.
Reward if helpful,
Karthik -
Hi all,
I have two tables:
CRETE TABLE T1 (T1_COL1 NUMBER, T1_COL2 NUMBER)
CRETE TABLE T2 (T2_COL1 NUMBER, T2_COL2 NUMBER)
T1 may or may not have records. T2 always has records. There are two scenarios.
Scenario 1:
=======
SELECT * FROM T1 returns five rows, and SELECT * FROM T2 returns 10 rows.
Now I need the five rows from T1.
Scenario 2:
=======
SELECT * FROM T1 returns zero rows, and SELECT * FROM T2 returns 10 rows.
Now I need the 10 rows from T2.
In other words, if records present in T1, I need them all. If not, I need records from T2.
There are no common columns (for joins).
Now need a single query to achive this. I tried set operators, CASE and DECODE. But I'm unable to solve it.
Please help. Thanks in advance.Iniyavan wrote:
Yes, Justin. I'm sure that this is the way it's modelled. I also find it's tough and odd.Are you sure it's the right way for that data to be modeled? I understand that's the way it is being modeled, but a data model change may be the best option.
Is there any other way, which is simpler, without using RANK?That's the simplest option I can think of. You could also do something like
SELECT t1_col1, t1_col2
FROM (
SELECT t1_col1, t1_col2, rownum rn
FROM (
SELECT t1_col1, t1_col2
FROM (
SELECT t1_col1, t1_col2, 1 tbl
FROM t1
UNION ALL
SELECT t2_col2, t2_col2, 2 tbl
FROM t2
ORDER BY tbl
WHERE rn = 1I'm not sure that's any simpler...
Justin -
I have two tables - table1 and table2 - that have the exact same schema. There are three fields that can be used to compare the data of the two tables, field1, field2, and field3. When there are matching rows in the two tables (table1.field1/2/3 = table2.field1/2/3)
I want to replace table1.field4 with table2.field4 and replace table1.field5 with table2.field5.
I have worked with the query but have come up with goobly goop. I would appreciate any help. Thanks.If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ; -
Records from two tables in different DB's
I have two tables (in different DB's) that I need to build
results from. I want to return results from all records in table A
and when a matching record in table B is found, retrieve the value
of a sqlbit field. The catch is that there may or may not be any
records in Table B that match Table A, and there may be more than
one record in Table B, but always only one record for Table A.
Table A is [Order] (yes I know, a reserved word - not my
design) and Table B is tblOrderFollowup - here is my current SQL
statement:
****************BEGIN SQL*************************
SELECT o.StoreID AS xStore
, o.Time AS dCreated
, o.ID AS xPurchase
, c.FirstName AS sFirstName
, c.LastName AS sLastName
, c.Company AS sCompany
, c.ID AS xCustomer
, o.Type AS xType
, o.Closed AS bClosed
, o.Tax AS nTax
, fu.OrderID AS xFUOrder
, fu.bComplete AS xFUComplete
FROM [Order] o
INNER JOIN Customer c
ON o.CustomerID = c.ID
AND o.StoreID = c.StoreID
LEFT OUTER JOIN db2.dbo.tblOrderFollowup fu
ON o.ID = fu.OrderID
AND o.StoreID = fu.StoreID
WHERE o.StoreID IN ( #allowableStoreIDs# )
AND o.StoreID = <cfqueryparam cfsqltype="cf_sql_integer"
value="#FORM.StoreID#" />
AND o.Time >= <cfqueryparam
cfsqltype="cf_sql_timestamp"
value="#CreateODBCDateTime(StartOfDay(FORM.dFrom))#" />
AND o.Time <= <cfqueryparam
cfsqltype="cf_sql_timestamp"
value="#CreateODBCDateTime(EndOfDay(FORM.dTo))#" />
AND o.Closed = <cfqueryparam cfsqltype="cf_sql_bit"
value="1" />
ORDER BY o.Time DESC
***********END SQL**********************
The problem here is that when I have more than 1 record per
OrderID/StoreID pair in Table B, I get more than one result - I
only want one. I am guessing I need a sub query, but don't know how
to go about doing that at all ...You say you want only one result. Do you know which one you
want?
By the way, your query is probably not giving you the right
answer. My experience is that if you do this:
select stuff
from table1 left join table2 on something
where table2.somefield = somevalue
you get the wrong answer. What I do instead is,
select stuff
from table1 left join
(select stuff from table2
where whatever) need_an_alias on somthing -
Delete records from two tables
Hi All,
I have two tables (tableA and tableB) and i have four combination primary key.
How can I delete the records from tableA that are not in tableB?
In my sample below I need to delete the records from year 2013.
I have a loop to insert the new ones.
Thanks
Johnny
create table tableA(
keyA_id number,
keyB_id number,
keyC_id number,
keyD_id number,
amount number,
CONSTRAINT "PK_TABLEA" PRIMARY KEY (keyA_id, keyB_id, keyC_id, keyD_id)
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2011,10);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2012,40);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2013,20);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2011,10);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2012,30);
insert into tableA(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2013,20);
create table tableB(
keyA_id number,
keyB_id number,
keyC_id number,
keyD_id number,
amount number,
CONSTRAINT "PK_TABLEB" PRIMARY KEY (keyA_id, keyB_id, keyC_id, keyD_id)
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2011,10);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2012,40);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,1,2014,40);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2011,10);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2012,30);
insert into tableB(keyA_id,keyB_id,keyC_id,keyD_id,amount)
values(1,1,2,2014,30);r you trying to do something like below ?
Delete from TableA A
where not exists (select 1 from TableB B where
A.keyA_id=B.keyA_id and
A.keyB_id=B.keyB_id and
A.keyC_id=B.keyC_id and
A.keyD_id=B.keyD_id) -
How to access records from two tables which have no relation
Hi,
I trying to generate a report where i need to print the company details at the top of the page and invoice details of that down the page.There is no relation between these two tables.I am not able to write two queries for one report.Pls some one assist me in getting this thing done.
Regards,
Tulacenath.Hi Tulacenath
So your invoice table does not have a reference to the customers (companys) that the invoices belong to?
Tim -
Matching records from two tables even when the ID of a person is null.
I have a MySQL named Natural Systems which is a magazine account that it member's will both sell handmade items wherein the proceeds will go into the Natural Systems account and each member also give a weekly donation. All of the proceeds will help toward the printing of the subsequent volumes. both of the selling of handmade items and the weekly dues happens during the same week or the same magazine volume number. I am trying to write a query that will pull both of the sales as well as the weekly dues payments weather they have paid or not.
SELECT foiid, trim(concat(name.fname,' ',name.lname)) AS no_ns, nspayamt, DATE_FORMAT(nspaydate, '%m/%d/%Y') FROM name LEFT JOIN nspay ON nspayfoiid = foiid and volume = '27' WHERE nspayfoiid is null AND type = 'Registered' AND city = 'richmond' AND status = 'a' group by foiid ORDER BY no_ns
This code will bring up the following names of those who did not pay weekly dues during volume 2:
Christopher Gabb
Michael banks
Timothy Hardin
However there is another table I wish to call the same Individuals who sold magazine during the same week of volume 27
SELECT trim(CONCAT(name.fname,' ',name.lname))AS Sold,
round(sum(fcnsales.salesamt)) as TOTAL_Mags_SOLD FROM name, fcnsales WHERE fcnsales.salesfoiid = name.foiid
AND fcnsales.salesvolume '27' GROUP BY name.foiid ORDER BY TOTAL_mags_SOLD desc;
This above code produces the following results:
Sold TOTAL_Mags_SOLD
Christopher Gabb 50
Michael banks 36
Timothy Hardin 12
I would like to combine the two queries to produce the following
Sold TOTAL_Mags_SOLD nspayamt
Christopher Gabb 50 none
Michael banks 36 none
Timothy Hardin 12 none
can anyone give me a direction to go to?If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ; -
Display records from two tables in a Repeat Region
I have 2 tables tblNames and tblResults
tblNames
NamesID PK
FirstName
LastName
Address1
Addrees2
tblResults
ResultsID PK
NamesID FK
ResultsInfo
ResultsDate
Results table has a foreign key NamesID containing primary
key of Names table.
I am trying to show a repeat region of results, with a column
showing LastName of tblNames depending on the ResultsID
I have 2 recordsets, rsNames and rsResults but I'm having
trouble showing relevant LastName.Create a new recodset or modify one of the old ones with this
sql:
SELECT LastName, ResultsInfo, ResultsDate
FROM tblResults INNER JOIN tblNames USING (NamesID)
ORDER BY LastName
This will produce a list of LastNames and associated info
Dave Buchholz
I-CRE8
www.i-cre8.co.uk
Skype ID: I-CRE8
"Swn-Y-Mor" <[email protected]> wrote in
message
news:f1ndo2$cp9$[email protected]..
>I have 2 tables tblNames and tblResults
>
> tblNames
> --------
> NamesID PK
> FirstName
> LastName
> Address1
> Addrees2
>
> tblResults
> ----------
> ResultsID PK
> NamesID FK
> ResultsInfo
> ResultsDate
>
> Results table has a foreign key NamesID containing
primary key of Names
> table.
>
> I am trying to show a repeat region of results, with a
column showing
> LastName
> of tblNames depending on the ResultsID
> I have 2 recordsets, rsNames and rsResults but I'm
having trouble showing
> relevant LastName.
> -
Help with Reading values from static table in a .pdf file
Hi guys,
Pls try to clear this doubt of mine.
I basically have 2 files. Both are .pdf extension and they have tables in them. I need to compare certain values in one file with the corresponding values in the other table in the second file.
I need to do this programatically in c# . net
I have tried using packages like pdfbox and stuff which convert the pdf file into text. But cant I get the table as an object or something using which I can access the required rows and columns?
Also, these tables are static information. They are not a part of a form or anything like that.
Please help me with this.
Thanks.The document is corrupt. Try a backup.
-
Need to Create Search Help Based on Condtions from one table to another tab
Hi All,
I have a table like ZGROUP Which contains the data below
Filed name Filed Name Filed Name
ZGROUP ZTYPE ZTEXT
Entries
ABC P TEXT FOR
C P SDFNSDFKLN
DDDD PSG TEPRTPERERTWERT
DEF P TEST
FFFFF PSG
SEF PS SDFSDFLASLDFNASDLFN
XYZ PS TESTING
Whree P is Product , PS- Point of Sales, PSG-Sales Group
Now i am going to crate another ZPROUDCT TABLE
FIELDNAME FIELDDESCRITPON
PRODUCT PROD_DESC
Entry
abc pRELATED ENTRY
My Questions
1) ZGROUPS table has 3 kinds of data P, PSG, PS type records,
1) In Table ZPROUDCT , I want to create search help only P records for Table Zproduct of the field Product FROM zGROUPS table
2) In Table Zsales , I want to create search help only PS records from ZGROUPS table
3) In Table ZPSG, I want to create search help only PSG records from table ZGROUPS
is it possible to create search help from One Master Table(ZGROUPS) table to other tables based on conditions.
Please help me.
very urgent
Regards,
Rajuif <condition>
AT SELECTION-SCREEN ON VALUE-REQUEST FOR <field>
SELECT <field>
FROM <table>
INTO TABLE i_tab
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' "function module to provide f4 help to sold-to-party
EXPORTING
retfield = "XXXX"
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = '<field name>'
value_org = 'S'
TABLES
value_tab = i_tab
endif.
lkike this u can check the condition and selec the data from table and assign it into one internal table and then call the FM it will give the f4 help to particular field
reward if helpful
regards,
Khan. -
SQLite - populating a list with records from a table
I'm fairly new to FB and AIR but have run myself through some tutorials regarding event handling and code structure. I have made some progress with an app for my Android 'phone which uses and SQLite database.
I've created the DB and stored it under assets.
I can open and read from it and store the records from a table in the DB to an array and then put the records into an arraycollection.
via the list dataprovider I then can assign the records to the list and they show up at runtime in the list.
I then presumed that the list changehandler event would allow me to assign the selecteditem in the list to a label control. Unfortunately the label control just gets 'object object' displayed when a list item is selected - almost a sif the list were empty.
I cannot work out how to paste the code into this forum message but any advice on either of these problems would be greatly appreciated.
ThanksI'm fairly new to FB and AIR but have run myself through some tutorials regarding event handling and code structure. I have made some progress with an app for my Android 'phone which uses and SQLite database.
I've created the DB and stored it under assets.
I can open and read from it and store the records from a table in the DB to an array and then put the records into an arraycollection.
via the list dataprovider I then can assign the records to the list and they show up at runtime in the list.
I then presumed that the list changehandler event would allow me to assign the selecteditem in the list to a label control. Unfortunately the label control just gets 'object object' displayed when a list item is selected - almost a sif the list were empty.
I cannot work out how to paste the code into this forum message but any advice on either of these problems would be greatly appreciated.
Thanks -
Export specific records from all table? Please help me with my query
hi
there are around 200 tables, I want to take a export of all tables of xyz schema.
My requirement is just a few records of primary key and their relevant records from other tables to be exported by using exp or expdp utility.Hi Toni...
Thanks for your reply.
Could you please help me understand how to user this expdp query...
and what exactly should i mention in the parfile. I want all relevant records from all tables of primary key. please help me to write a query accordingly. -
Need assistance searching records from multiple tables - Please Help!
Hi, I've been trying to solve this problem for several weeks now, and I have exhausted all of my knowledge and experience. I need help, and I hope someone here can give me some direction.
I am using VB 2008, and the CR that comes bundled with VS 2008 Pro. My database is a SQL Server 2005 CE v3.5 (a *.sdf file). I am connecting to the database through a dataset, and I am displaying the report in a CrystalReportViewer.
My dataset consistes of two tables:
1) tblCustomers which has a primary key "CustID", and contains only customer contact and personal information.
2) tblDateVisited which has a primary key of "VisitID", but it also has a column titled "CustID". Basically, every time a customer visits the business, details of that visit are recorded in tblDateVisited, and that record is associated with the customer by their CustID.
Here's what I'm trying to accomplish: I want to be able to display only Customer records when the customer has visited and that visit matches certain criteria. Right now, I am trying to match visits from the "tblVisitDate.PlayerType" column. If the customer has ever had a visit where they matched a particular player type, I want to see those customer records.
I don't know what I'm doing wrong, though. I can search a dataset if I am only querying one table and pulling records from that table. However, whenever I try to add a second table and perform queries on that table to get records from the first table, I can't return any records.
If it helps, I am trying to use one CrystalReportViewer to display multiple reports (user choice) and here's how I'm loading the report into the viewer:
Me.tblCustomersTableAdapter.Fill(Me.dsPlayerTypeReports.tblCustomers)
Me.tblDateVisitedTableAdapter.Fill(Me.dsPlayerTypeReports.tblDateVisited)
Me.ReportFile.SetDataSource(dsPlayerTypeReports.Tables(1))
I am suspicious that my problem is in the Tables(1) method. It confuses me that I can only assign one table as a datasource when I obviously need access to two tables to make this selection work.
Whatever the case, I'm at the end of my rope with this one. I'm not prone to giving up, but I'm at a dead end currently.
Any attempt to assist me with this will be greatly appreciated, successful or not.
Thanks in advance!
-WillNo, I am connected via ADO.NET. I don't think SQL CE can connect through ODBC (or if it can, I haven't been able to figure out how, yet). So this isn't a stored procedure.
When I examine the link, I can only choose an Inner Join or a Left Outer Join. Right Outer and Full Outer are not available. Could this be a problem with the dataset I'm using?
Could you explain what you mean by display all of the records and then choose the selection criteria?
Maybe you are looking for
-
I have a diabetes monitor free style insulinx how do i get it to work on the MAC lion version
Hi Can anyone help. I Have a diabetes monitor free style insulinx but it does not work on the lion operating system. Has anyone managed to get this to work. Initially it started to load the application but then stopped and would not work. Any ideas,
-
My number is greyed out in iMessage, I can only use my email, help me!
I've just updated my iPhone 5 to iOS 7 and now when I iMessage people it comes up with my email address and i went into messages in settings and my number is greyed out with my email address under it ticked, I've tried everything such as turning it o
-
How to get data using BEx variable
I've build a universe upon a Bex query with a variable. When refreshing a WeBi report upon this universe with the filter (BEx variable) it works fine and returns data. The same does the QaaWS. But when I use this QaaWS as a source for Xcelsius dashbo
-
How do I fax a signed document
I am trying to fax a transcript request form. When I select the fax option the form is requesting an email address for the recipient. In parenthesis it states that I can use a fax number but when I enter the fax number I get an error stating incorrec
-
i am having problem with my system preference settings. whenever i try to open it, it is not responding. I am using OS 10.8.4. PLEASE HELP ...