Collect variables from from different tables
Good evening!
I want to make a table with variable green from table uno,
and variable blue from table dos,
and variable yellow from table tres,
and only of variable yellow equals 1 to 9.
my syntax is as below. what is wrong, what should i do instead? Many thank's!
exec("select a.id, a.green, b.blue, c.yellow from uno as a left join dos as b on (a.id=b.id) left join tres as c on (a.id=c.id) where c.yellow between '1' and '9'")
Try this
exec('select a.id, a.green, b.blue, c.yellow from uno as a left join dos as b on (a.id=b.id) left join tres as c on (a.id=c.id) where c.yellow between ''1'' and ''9''')
--Prashanth
Similar Messages
-
How to use dynamic select query which queries from 3 different table.
Hi All,
I am new to Toplink, i would like to use a named query to select some of the columns from 3 different tables with dynamic where clause.
I have used the following lines. Please tell me how to get code for the dynamic where clause.
First try :
Vector objPersons = (Vector)session.executeQuery("findPersonByGlobalID",Person.class,vQueryArguments);
The above method is not returning the vector or collection.
Second Try:
ReadAllQuery query = new ReadAllQuery(Person.class);
query.useCollectionClass(LinkedList.class);
LinkedList person = (LinkedList) session.executeQuery(query);
The second try is returning the collection but, this fetches all the record from the table.
1. How to query for range of records?
2. How to query from multiple tables for some range. How to use dynamic range values ?
Please reply with your answers or some pointers would help.
Thanks and Regards,
Vijay.BHi,
Did you try using a SQLCall ? It might be able to satisfy you requirements .. :-
Employee employee = (Employee) session.executeSelectingCall(
new SQLCall("SELECT * FROM EMPLOYEE WHERE EMP_ID = 44")
);You can get more information here :-
http://www.oracle.com/technology/products/ias/toplink/doc/1013/MAIN/_html/qrybas004.htm
Regards,
Sandeep -
How to create a foreign key for the table from two different tables?
Hi All,
I have a three table like below. In the below table SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK will be having the primary key for NAME column. The same SAMPLE_CONS3_CHECK table also having the primary key for NAME column and forieign key for SAMPLE_CONS_CHECK and SAMPLE_CONS2_CHECK tables. See the below code 2
code 1:
CREATE TABLE SAMPLE_CONS_CHECK
(NAME VARCHAR2(10),
SERIES VARCHAR2(5)
CREATE TABLE SAMPLE_CONS2_CHECK
(NAME VARCHAR2(5),
MODEL NUMBER
CREATE TABLE SAMPLE_CONS3_CHECK
(NAME VARCHAR2(5),
MODEL_NO NUMBER
)code 2
alter table SAMPLE_CONS_CHECK
add constraint SAMPLE_CONS_CHECK_pk primary key (NAME)
alter table SAMPLE_CONS2_CHECK
add constraint SAMPLE_CONS2_CHECK_pk primary key (NAME)
alter table SAMPLE_CONS3_CHECK
add constraint SAMPLE_CONS3_CHECK_pk primary key (NAME)
ALTER TABLE SAMPLE_CONS3_CHECK ADD
CONSTRAINT SAMPLE_CONS3_CHECK_FK1 FOREIGN KEY
NAME
) REFERENCES SAMPLE_CONS_CHECK
NAME
) ON DELETE CASCADE;
ALTER TABLE SAMPLE_CONS3_CHECK ADD
CONSTRAINT SAMPLE_CONS3_CHECK_FK2 FOREIGN KEY
NAME
) REFERENCES SAMPLE_CONS2_CHECK
NAME
) ON DELETE CASCADE;From the above schenario i am able to insert the data to SAMPLE_CONS3_CHECK table. But the parent data is already available in the parent table. The problem is here two different constarints from two different tables. While inserting, it is checking from both the tables whether the parent is exist or not.
How can i solve this problem? Can anyone halp me about this?
Thanks
Edited by: orasuriya on Aug 8, 2009 2:02 AMActually the design is completely incorrect.
What you say is
I have
'foo', 'foo series'
'foo','foo model'
'foo',666
By virtue of table3 referring to both table1 and table2.
This means you actually need to have 1 (one) table:
'foo','foo series','foo model', 666
And the 'problem' disappears.
Sybrand Bakker
Senior Oracle DBA -
Resukt:Get number of rows from 3 different table...?
Hi All,
I need to find out number of rows from 3 different table for the same conditions. Instead of writing 3 queries, is it possible to get it thru one query?
For example, i need to find out number of rows in tables where name = 'Ameet' from 3 different table, i will end writing 3 queries.
1. select count(1) from table_a where name = 'Ameet';
1. select count(1) from table_b where name = 'Ameet';
1. select count(1) from table_c where name = 'Ameet';
Is it possible to write a single query to get result of all above 3 queries?
result:
table_a table_b table_c
34 44 2One way:
SELECT (SELECT COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet') AS TABLE_A
, (SELECT COUNT(*) AS CNT FROM TABLE_B WHERE name='Ameet') AS TABLE_B
, (SELECT COUNT(*) AS CNT FROM TABLE_C WHERE name='Ameet') AS TABLE_C
FROM DUALIf you want the total:
SELECT SUM(CNT)
FROM
SELECT COUNT(*) AS CNT FROM TABLE_A WHERE name='Ameet'
UNION ALL
SELECT COUNT(*) FROM TABLE_B WHERE name='Ameet'
UNION ALL
SELECT COUNT(*) FROM TABLE_C WHERE name='Ameet'
) -
Selecting data from two different tables.
Do we need to use join two tables with primary/foreign key while trying to use select statement for getting data from those to table.? If no who can i go about do it.
872959 wrote:
If i am using From clause to get data from two different tables, is it necessary that both tables have column of identical data in them.In general, they ought to (or you need to join in a third table that tells you how to map rows from one table to rows of the other table).
It is not strictly necessary that there be any join condition between tables. If you don't provide a join condition, Oracle has to do a Cartesian product. That means that if there are n rows in one table and m rows in the other, the result set will have n * m rows. It is very rarely a good idea to write queries that do Cartesian products but it does occasionally happen.
Justin -
Create one tables from 2 different tables
Hi,
How I can create one table from 2 different tables. Source tables have data and I want to include it in new table.
I try this:
create table NEW_ONE
select * from OLD_ONE
union
select * from OLD_ONE2;
But it didn't work correctly :/I don't have any error. This syntax create table NEW_ONE, but this table have columns only from OLD_ONE table :/ There aren't any column from OLD_ONE2 :/ Any suggestions?
I don't forget about "as" in my query, only in this post.
Edited by: tutus on Sep 8, 2008 6:36 AM -
TSQL Help Counting from 2 different tables.
I am trying to Count the number of items from 2 different Tables (A & B)
But if I have a count in A and B I get 2 separate records. Id like them to be on the same record.
Below is what I currently have.
SELECT
CUST.ID,
CUST.ID_Name,
COUNT(TABLEA.Item_ID) AS itemCount,
0 AS itemCountShipped,
0 AS itemCountTotal
FROM TABLEA LEFT OUTER JOIN CUST ON TABLEA.ID = CUST.ID
WHERE CUST.Customer_Type = 'I' OR CUST.Customer_Type = 'C'
GROUP by CUST.ID,CUST.ID_Name
UNION ALL
SELECT
CUST.ID,
CUST.ID_Name,
0 AS itemCount,
COUNT(TABLEB.Item_ID) AS itemCountShipped,
0 AS itemCountTotal
FROM TABLEB LEFT OUTER JOIN CUST ON TABLEB.ID = CUST.ID
WHERE CUST.Customer_Type = 'I' OR CUST.Customer_Type = 'C'
GROUP by CUST.ID,CUST.ID_Name
ORDER BY CUST.ID_Name
Ideally, I would like to have the all Counts to be calculated in the TSQL and have 1 record per ID.....and if there was a way to add those 2 up in the SQL that would be good too. I currently process my data to give me the itemCountTotal.
Any help would be greatly appreciated.On this portion "a.ItemCount, b.ItemCountShipped,"
These fields are not on TABLEA or TABLEB, but if I remove the TABLE name from the front then TSQL says it cant find those fields.
SELECT COALESCE(a.ID, B.ID) as ID, COALESCE(a.Name, b.Name) as Name,
a.ItemCount, b.ItemCountShipped,
COALESCE(a.ItemCount,0) + coalesce(b.ItemCountShipped,0) as itemCountTotal -- shipped + original count? -
Creating LOV from 2 different tables
I tried doing some searches on this, but haven't been able to find an answer. Can I create an LOV (to populate a select list) from two different tables? Both tables have the exact same column names/datatypes, just different data.
Or if this isn't possible, should I just create a new table, and then do a union query to populate it with the values from both of these tables? Just wondering if anyone's had experience with this situation. Thanks!Hmm. That is weird. Wonder why it's not working for me.
The SORT_ORDER column appears in both tables. I was hoping to be able to sort by the number value that appears in this column in both tables (could duplicate values in this table be causing an issue?).
I even tried changing it to:
SELECT DISPLAY_AS d1, CONTENT_KEY v1
FROM SER_LISTS_JOB_TYPE
WHERE ACTIVE = 'YES'
UNION
SELECT DISPLAY_AS d2, CONTENT_KEY v2
FROM SER_LISTS_COMPANY_TYPE
WHERE ACTIVE = 'YES'
ORDER BY SORT_ORDERBut still get the same error message.
Message was edited by:
taneal
OK. It appears the ORDER BY SORT_ORDER was causing the issue. I took it out and it worked. The only problem is that I have 1 duplicate entry, called "Other" that now appears twice in my LOV. Any thoughts on this? The value of CONTENT_KEY is different, but the value for DISPLAY_AS is the same. Is there anyway to pull out one of these? -
1 Graph from 2 different tables?
I'm trying to build some bar charts with two matching data sets that are in two different tables (they're big data sets). I don't want to have to copy the specific data I want from each Table into a 3rd table just to build a chart with it. Can I use data from two different tables in the same chart? i.e. the data looks like this in the chart but is in two different tables?
Table1 Table2
Data 20 25
Data 35 22
Data 36 27...
Does this question make sense? Thanks for any help.
Message was edited by: Aaron Smith6
Message was edited by: Aaron Smith6If I understand well the User Guide, we may chart datas from different tables BUT it works with rows of different tables, not with columns of different tables.
+• To add a chart based on data in more than one table, first select a single table or contiguous range of cells and create a chart, then click Charts in the toolbar, and choose a chart type. Select the chart and hold down the Command key while clicking or dragging cells in another table to add their data to the chart.+
Yvan KOENIG (from FRANCE vendredi 9 janvier 2009 21:37:41) -
Selecting from 2 different tables
is this possible?
i just want to select from two different tables in one select statement and they have the same WHERE clauseSELECT
a.pkggrp,
a.pkgtype,
a.area,
a.process,
a.ww,
count(a.ww) as LOTSGATED,
sum(a.samplesize) as SUMSAMPLESIZE,
sum(a.total_defects) as SUMTOTALDEFECTS,
sum(case a.auditresult when 'pass' then 1 else 0 end) COUNTPASS,
sum(case a.auditresult when 'fail' then 1 else 0 end) COUNTFAIL,
case sum(case a.auditresult when 'fail' then 1 else 0 end)
when 0 then 0
else round(sum(case a.auditresult when 'fail' then 1 else 0 end) / count(a.ww) * 100,2)
end LRR,
case sum(case a.auditresult when 'fail' then 1 else 0 end)
when 0 then 0
else round(sum(case a.auditresult when 'fail' then 1 else 0 end) / sum(a.samplesize) * 1000000,0)
end PPM,
count(c.itrnum)
FROM
t_prodproc_monitoring a, t_itr c
WHERE
a.ww=c.ww
and a.ww between 1 and 50
and c.ww between 1 and 50
GROUP BY
a.pkggrp,
a.pkgtype,
a.area,
a.process,
a.ww
ORDER BY
a.pkggrp,
a.pkgtype,
a.area,
a.process,
a.ww ascthis gave me a
"c". "ww": invalid identifier -
List rows with a certain value from a different table?
Hi,
I'm trying to list certain rows from a different table. Similar to the filter feature, kind of like a report.
To be specific, I have 12 tables (Jan-Dec) with many entries each (as rows). Each row has a date, text and further data. Now I want to create an additional table that lists rows from the other tables that have a certain date.
I would like to just enter that date in a header row cell so I can make a quick query. Using LOOKUP only shows the first row of that date. Is that even possible?Hi papalapapp,
If you don't mind using a script, you're using Numbers 3, and all of your monthly tables are on the same sheet, then you could do something like this:
Copy-paste script to Script Editor
Enter date you want to filter on in the designated filterCell (here A1 of the Extract table). Make sure it is formatted exactly like the dates in the monthly tables.
Clear any existing values from the Extract table, and make sure there are enough blank rows.
Click the run button in Script Editor.
SG
property targetTable : "Extract"
property filterCell : "A1"
tell application "Numbers"
tell document 1's active sheet
set dateFilter to table targetTable's cell filterCell's formatted value
--get all data in tables (excluding Extract table)
set vv to {}
repeat with t in tables
if t's name is not targetTable then
set vv to vv & t's rows's cells's formatted value
end if
end repeat
--filter data
set vvFilt to {}
repeat with i from 1 to vv's length
if vv's item i's item 1 is dateFilter then
set vvFilt to vvFilt & {vv's item i}
end if
end repeat
--write filtered data to table
tell table targetTable
repeat with r from 1 to (vvFilt's length)
repeat with c from 1 to vvFilt's item 1's length
set row (r + 1)'s cell c's value to vvFilt's item r's item c
end repeat
end repeat
end tell
end tell
end tell -
Sum two different columns from two different tables
Can you select and sum two different columns, from two different tables in the same sql statement?
i.e.
table1
Item----OnHand_Qty
A--------10
A--------15
B--------10
B--------10
C--------20
table2
Item----Trx_Qty
A--------2
A--------4
A--------6
B--------1
B--------1
C--------4
I'm looking for the following results from a query
Item----Sum(Onhand_Qty)---Sum(Trx_Qty)
A--------25Like this?
SQL> create table table1 (item,onhand_qty)
2 as
3 select 'A', 10 from dual union all
4 select 'A', 15 from dual union all
5 select 'B', 10 from dual union all
6 select 'B', 10 from dual union all
7 select 'C', 20 from dual union all
8 select 'D', 30 from dual
9 /
Tabel is aangemaakt.
SQL> create table table2 (item, trx_qty)
2 as
3 select 'A', 2 from dual union all
4 select 'A', 4 from dual union all
5 select 'A', 6 from dual union all
6 select 'B', 1 from dual union all
7 select 'B', 1 from dual union all
8 select 'C', 4 from dual union all
9 select 'E', 3 from dual
10 /
Tabel is aangemaakt.
SQL> select nvl(t1.item,t2.item) item
2 , t1.sum_onhand_qty
3 , t2.sum_trx_qty
4 from ( select item, sum(onhand_qty) sum_onhand_qty
5 from table1
6 group by item
7 ) t1
8 full outer join
9 ( select item, sum(trx_qty) sum_trx_qty
10 from table2
11 group by item
12 ) t2
13 on (t1.item = t2.item)
14 /
I SUM_ONHAND_QTY SUM_TRX_QTY
A 25 12
B 20 2
C 20 4
E 3
D 30
5 rijen zijn geselecteerd.Regards,
Rob. -
Can't get table field from two different tables if named same
select c.notes, o.notes
from cusomters c, orders o
:does not work in getting the RS.
:if i change database to:
select c.customer_notes, o.order_notes
from cusomters c, orders o
:then it works.
:i make PURE DYNAMIC META SQL database
applicaitons, and i need for abstract SQL tables.
i have the same problem in getting
the max values:
select
max(height),
max(weight),
max(age)
from person_stats
group by geographical_areaWhen you select from 2 different tables you need to join them on some condition, otherwise it has no idea how to associate the 2 tables together.
try select c.notes, o.notes from cusomters c, orders o where c.customer_id = o.customer.id or whatever the join fields are.
For the group by I believe you have to include the field that you group by:
select geopraphical_area, max(height), max(weight), max(age) from person_stats group by geographical_area
give them a try
Jamie -
Hello Community
Using Visual Studio 2008 I have created a Windows Forms Application in which I created
Embedded Reports (rdlc).
The embedded reports (rdlc) uses Matrix(s).
Now on this one rdlc I have dragged 2 Matrix(s) onto the body.
One of the Matrix datasource dataset name and table name is "DataSet1_Table1.
A cells in the Matrix has a total column on the end as follows:
=FormatNumber(Sum(Fields!fld1.Value)+Sum(Fields!fld2.Value)+Sum(Fields!fld3.Value)+Sum(Fields!fld4.Value)+Sum(Fields!fld5.Value),"0")
The other Matrix datasource dataset name and table name is "DataSet2_Table2.
The cell in this Matrix has a total column on the end as follows:
=Sum(Fields!fld1.Value)+Sum(Fields!fld2.Value)+Sum(Fields!fld3.Value)+Sum(Fields!fld4.Value)+Sum(Fields!fld5.Value)
As you can see each Matrix has a different table.
I would like to add the total columns from each table in each Matrix but I haven't been
able to do it successfully. If I have to drag another Matrix or a Textbox on the
body to do it that is okay and/or add another/different formula to a cell onto the body that is
okay too.
So my question is how can I add the contents of the total in cell from each table in each matrix
which will create the "grand total"?
Thank you
ShabeautIt is possible to reference SSRS elements directly using the ReportItems collection. If your total tablix cell is outside of yoour matrix groups, you can use this collection to accomplish what you want:
=ReportItems!Matrix1Total.Value + ReportItems!Matrix2Total.Value
where Matrix1Total and Matrix2Total is the name of the cell that contains your totals. Note that for this to work, the cell name must be unique. If the total cell is inside a group, it will be repeated once for each instance of the group and will not be
unique.
You may be able to do it using the Sum aggregate and specifying the dataset for the scope variable:
=Sum(Fields!fld1.Value, "DataSet1")+Sum(Fields!fld2.Value,
"DataSet1")+Sum(Fields!fld3.Value,
"DataSet1")+Sum(Fields!fld4.Value,
"DataSet1")+Sum(Fields!fld5.Value,
"DataSet1")+Sum(Fields!fld1.Value,
"DataSet2")+Sum(Fields!fld2.Value,
"DataSet2")+Sum(Fields!fld3.Value,
"DataSet2")+Sum(Fields!fld4.Value,
"DataSet2")+Sum(Fields!fld5.Value,
"DataSet2")
This will work as long as you are not filtering the dataset in your Matrix properties. If you are, those
filters will not apply to this expression and the numbers will not total correctly.
"You will find a fortune, though it will not be the one you seek." -
Blind Seer, O Brother Where Art Thou
Please Mark posts as answers or helpful so that others may find the fortune they seek. -
How to populate an internal table from three different tables
My requirement is to populate an itab by retrieving data from three diff db tables,
ekko,ekpo and Ekbe.
below is the code for data retrieval .
SELECT EBELN INTO TABLE IT_EKKO FROM EKKO WHERE EBELN IN S_EBELN.
IF NOT IT_EKKO[] IS INITIAL.
SELECT EBELP TXZ01 NETWR BUKRS INTO CORRESPONDING FIELDS OF TABLE IT_EKPO FROM EKPO FOR ALL ENTRIES IN IT_EKKO
WHERE EBELN EQ IT_EKKO-EBELN.
IF NOT IT_EKPO[] IS INITIAL.
SELECT EMATN WAERS WERKS GJAHR BEWTP INTO CORRESPONDING FIELDS OF TABLE IT_EKBE FROM EKBE FOR ALL ENTRIES IN IT_EKPO
WHERE EBELN EQ IT_EKPO-EBELN
AND EBELP EQ IT_EKPO-EBELP
AND BEWTP EQ 'E' OR BEWTP EQ 'Q'.
ENDIF.
ENDIF.
please tell me how to populate data from it_ekko,it_ekpo and it_ekbe into an internal table ITAB.Hi Mayana,
You take one final structure & final internal table, & within that structure take all the fields which is required to be displayed as a final output.
for data fetching from different table, you take three different structures & three internal table for that, because into corresponding fields of table is not good for performance wise. Use into table syntax.
follow the below example:(similarly)
sort it_klah by key fields.
LOOP AT IT_KSSK INTO WA_KSSK.
READ TABLE IT_KLAH INTO WA_KLAH WITH KEY CLINT = WA_KSSK-CLINT
KLART = WA_KSSK-KLART.
IF SY-SUBRC EQ 0.
MOVE: WA_KLAH-OBJEK to WA_final-OBJEK.
Read another table........(2nd one)
IF SY-SUBRC EQ 0.
MOVE: ....................................
APPEND WA_final TO IT_final.
ENDIF.
clear wa_final.
ENDLOOP.
finally display it_final records.
Hope this can solve your problems.
Regards,
Tutun -
Getting Data from 2 different table and saving it in the third table
Hi,
My question is i have 2 different table where the data is stored. And Nothing is at Level0 and i don't need it.
Table A will be at Level1, this is a scroll and depending on this value the level2 grid will be populated with the values.
Say for example Table A is groups; data e.g., Cars, MotorBike etc
Table B will have the data for Group Cars: Holden, Toyota, Honda etc., MotorBike: Honda, Suzuki, Yamaha etc.,
Now lets say there are 3 divisions in the company AA , BB
Division AA has been allocated group Cars only
Division BB has been Allocated Both Cars and MotorBikes.
To do this i have used a query view where depending on the Division i choose the group and then i get the required fileds.
Now my Problem is that i need to save this data in table C but on the ad-hoc basis can't write a query with in the code to do that.
tried using work record on the scroll but i cant do that as well. Any Suggestions?
One more thing when the Page open this data should be pre-populated on the page depending on the division, the user will not be able to select anything from the prompt.
Edited by: 952330 on Aug 12, 2012 8:32 PMI hope I can clarify:
For our purposes here:
Table 1 = "Step 2 - Product Sizes"
Table 2 = "Option id Master"
Table 3 = "Export - Product Info"
Table 1:
The user would enter values for "productcode," "Horz," and "Vert"
"Size" would auto fill based on values in Horiz and Vert (I have this taken care of already).
Table 2: This is a completely static table that I want to search against. - Data from other tables in the doc does not alter or change the data in this doc.
We just want to look at table 2. Find the existing value in "table 2 : size" column that matches the "table 1 : size" column and then pull the "optionids" and "productprice" from that row.
Can the value from "Table 1 : Size" be used as a search term in "Table 2 : Size?"
Table 3: The user does not enter any values on this table.
"productcode" is pulled from table 1 - "Table 1 :: A5" = "Table 3 :: A5"
"optionids" and "productprice" are pulled from Table 2 columns "D" and "E" - however we do not know which Table 2 row it is pulling from until we enter data in Table 1.
As I'm writing this I'm realizing that
A. this is probably really confusing to you.
B. this may be impossible inside of numbers.
If you have some other method that would facilitate the same out come but be structured differently please let me know.
--- maybe to help you understand further what I am doing here is my current workflow:
I record the size of a piece of art.
Then I manually go to my "Option id Master" and find the same size.
I then copy the corresponding "optionids" and "productprice" cells. (these options control the prices displayed on my website)
I got to my "Export - Product Info" table and paste the values in the corresponding cells.
I was hoping to automate this as it takes a long time when you have hundreds of products.
Thanks for the help!
Maybe you are looking for
-
Dear SDN, In order to create a custom Report, I need to understand a Standard program, which at a certain point has a "GET objec" command. The structure objec, in this case, is related to the OBJEC table, which is related to the PCH database that was
-
SQL Server Cursor dioe not run in Hyperion Workspace
Hi all, I have a bqy file which runs fine in the design studio client (v9.3) however when I import it into the Workspace and try and run it i get the following error : An Interactive Reporting Service error has occurred.-SQL API: [SQLFetchScroll], SQ
-
Error in retrieving value from the inputfield.
Hi Experts, There is this behaviour I saw in WD which was understood by me. Let me explain it : I am doing a comparison scenario where I compare 2 products in a grid format. For this I have a table with a various types of variants. In this grid I hav
-
Premiere Pro cs6.02 mac 10.7.5 crashing every 2 min.
Hi group had a horrible summer where Premiere pro 6.0-6.01 crashed all the time meaning every 1-2 min. on both of my machines which are a 2012 macbook pro and imac, both have max ram and SSD drives. As most of you experienced after 10.7.5 and 6.02 ca
-
Firefox crashed unexpectedly and wouldn't restart. I rebooted and tried both regular start and safemode w/o add-ons and it still won't start. I then upgraded to Ver 6.1 and still won't open in safe mode. I'm using Vista 32 bit.