Select statement of severals tables with the same structure
Does anybody know - how to create a single select statement to count entries of several tables. These tables have the same structure and are connected by a foreign key to a - I would call master table. So in this master table - I have the names of all these others tables and what I want should look like this:
name__________ # entries
table_1_________100
table_2_________150
table_3__________80
Select table_name, count(table1.column1), count(table2.column1), count(table3.column1) from master, table1, table2, table3 Where master.id=table1.id OR master.id=table2.id OR master.id=table3.id Group By table_name
Thanks in advance
remo
If I understood your question correctly, this is what you (probably) need:
Select table_name, (select count(column1) from table1 Where master.id=table1.id), (select count(column1) from table2 Where master.id=table2.id), (select count(column1) from table3 Where master.id=table3.id)
from master
Similar Messages
-
Is it possible to have 2 tables with the same name in an Orable database?
Hello,
I'm a complete Oracle newbie so please excuse my question if it's stupid.
I was trying to create 2 tables with the same name using different tablespaces but it does not seem to work. Like this (second time just change the name of the tablespace):
CREATE TABLE test_tbl (
id INTEGER,
status VARCHAR2(10),
last_modified DATE DEFAULT SYSDATE
TABLESPACE tblspc1Is it in general in Oracle possible to acquire this goal?
Thanks a lot!
P.S. I have already created the needed tablespaces
CREATE TABLESPACE tblspc1 DATAFILE 'tblspc1.dbf' SIZE 10MEdited by: 808239 on 02-Mar-2011 02:18It is not possible to create two tables with same name in same schema.
A user can own one schema with his own name and another with the schema name SYS.
For this you have to grant sysdba privilage to the user and then have to connect using sys password or with the password specified in password file.
But this still you have to access to the table in sys schema using sys.table_name.
Hope Answered tthe Question. -
Does Pool & Cluster tables has the same structure in both Dictionary and Db
------------ Exists with the same structure both in dictionary as well as in database exactly with the same data and fields
a. Pool Table
b. Cluster Table
c. Transparent Table
d. All the above
To my knowledge, I know transparent table has the same structure in both Dictionary and database.
Can anyone tel me the answer for the above question.. whether it is
c. Transparent table
or
d. All the aboveTransparent Table:
A physical table definition in the database for the table definition which is stored in the ABAP Dictionary for transparent tables when the
table is activated. The table definition is translated from the ABAP Dictionary to a definition of the particular database.
A transparent table in the dictionary has one to one relationship with a table in the database.
For each transparent table in the data dictionary there is one associated table in the database.The database table has the same name, the same number of fields and fields have same names as the transparent table definition. Transparent tables are used to hold application data. Application data is master data or transaction data used by an application.
e.g. master data - table of customers
Transaction data - order placed by the customers.
Pooled tables:
Pooled tables can be used to store control data (e.g. screen sequences,program parameters or temporary data). Several pooled tables can be
combined to form a table pool. The table pool corresponds to a physical table on the database in which all the records of the allocated pooledtables are stored.
Pooled table in R/3 has a many to one relationship with a table in the database. For one table in the database there are many tables in the R/3 data dictionary.R/3 uses pooled tables to hold large number of very small tables. You might create a table pool if yoou need to create hundreds of small tables that each hold only a few rows of data.
Cluster tables :
Cluster tables contain continuous text, for example, documentation.Several cluster tables can be combined to form a table cluster. Severallogical lines of different tables are combined to form a physical record in this table type. This permits object-by-object storage or
object-by-object access. In order to combine tables in clusters, atleast parts of the keys must agree. Several cluster tables are stored in
one corresponding table on the database.
A cluster table is similar to pool table . It has many to one relationship with the table in the database.
They are used to hold the data from a few(approximatelly 2 to 10) very large tables. They would be used when these tables have a part of their primary keys in common and if data in these tables are all accessed simultaneously.A cluster is advantageous in the case where data is accessed from multiple tables simultaneously and those tables have at least one of their primary key fields in common.Cluster table reduce number of database reads and thereby improves performance. -
How do I create a target table with the same PK as the source table?
I am trying to create a target table in a mapping that will end up with the same primary key as the source table.
It is a simple map that simply uses a subset of the columns of the source table in the target table. I was wanting to create and bind a new table by dragging the columns I want from the source to the initially blank target table operator, change the column names and create a primary key to match the source table.
I can't seem to be able to create a constraint on the table in the mapping. I can create the constraint after the table is created and boound to the database object but the PK doesn't carry back into the mapping.
I need it in the mapping so I can use the UPDATE/INSERT operation and use the 'All Constraints' implementation. The mapping won't let me validate the object without the PK on it in the map.
Believe it or not folks, I am getting better at this.
Thanks very much for the guidance.
GaryHi Gary
You are close, you are really close... :-))
You need to do exactly as you propose plus one extra step. Build the map as you describe, binding the new table to the target. Then you edit the table definition to add the primary key and any other constraints you need. After this is the step that you are missing.
You need to do the following:
1. Go back and re-edit the map
2. Right click on the table
3. From the pop up menu, select Reconcile Inbound
4. Set any operators that you need for the UPDATE/INSERT
5. Save the map
6. Commit your changes
The first three steps above make the map read in the indexes and constraints that you set on the table. Finally, you need to deploy the table and then deploy the map.
Hope this helps
Regards
Michael -
Three tables with the same table name in the same user account
Windows XP with 10.2.0.1.0
What is the best strategy to handle the following tasks? Thanks in advance.
I need to have three different version of database with the same tablename and under the same user name.
So, I can choose which version of table I need.
For instance:
version1:
create table history(col1 varchar2(20),col2 varchar2(10) ,col3 varchar2(30));
with data:
version2:
create table history(col1 varchar2(20),col2 varchar2(10), col3 varchar2(30) ,col4 number ,col5 number);
version3:
history is an union by version1 and version2782150 wrote:
Windows XP with 10.2.0.1.0
What is the best strategy to handle the following tasks? Thanks in advance.
I need to have three different version of database with the same tablename and under the same user name.
So, I can choose which version of table I need.
For instance:
version1:
create table history(col1 varchar2(20),col2 varchar2(10) ,col3 varchar2(30));
with data:
version2:
create table history(col1 varchar2(20),col2 varchar2(10), col3 varchar2(30) ,col4 number ,col5 number);
version3:
history is an union by version1 and version2You can't unless you delete the previous table one table only with the same name -
Insert recordset in 2 tables with the same id
Hello,
I have two tables with the columns
CAR Client
clientId[FK] clientId [PK]
carId[PK] name
brand surname
type
I made a form with textfields
Brand
Surname
Name
Type
and I want thru Insert Recordset wizard to pass the cliendId in both tables.
How can I do this?You can do this by not relying on the recordset wizard and simply coding it yourself to INSERT data to tables. Or use wizard to insert into one table and modify code to allow insert into two tables.
best,
Shocker -
So can I have at the same time two plans?
I don't need for every apps, only Photoshop and Illustrator.Hi Barpaff,
Yes, you can add illustrator with the same account. So, you will be having two applications. 1) Creative Cloud Photography Plan and 2) Creative Cloud Illustrator single app.
You can add as many as single application in the same account but application should be different.
Let us know if you need more information on this.
Thanks,
Eshant Jindal -
WCF-SQL table operation on tables with the same name.
Hello,
My situation involves generating table operation schemas (Insert, Update, Delete, Select) for tables in two different SQL databases. These tables happen to have the same name. For the sake of discussion lets call the tables dbo.Customer. However,
these tables have different fields in them. When generating the schemas to be used by BizTalk, they end up as the same message type like so:
Database1: http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/Customer#Update
Database2: http://schemas.microsoft.com/Sql/2008/05/TableOp/dbo/Customer#Update
To my understanding, I can't simply change the namespaces or root nodes to be unique since this structure is expected by the SQL Adapter (shown here: https://msdn.microsoft.com/en-us/library/dd788023.aspx). I had a couple thoughts on a solution:
Use schema versions to differentiate between the two different table schemas.
Use a unique namespace and root node for the schemas. Then, create a custom pipeline component to modify them to the standard as it is sent to SQL server.
Modify the schema so support both tables with all columns in both tables.
I don't really like any of these solutions, so I am hoping somebody in the community has run into this situation before and has something better.
-RichardYou don't really have to do anything other than make sure the particular message gets routed always to the correct database.
Having duplicate MessageType's is only a problem if you're relying on the automatic resolution of the XmlDisassembler and that would only be a concern on the Response side.
To get around that, just create a custom Pipeline with the XmlDisassembler and set the Document Schemas list to only the one for that Port. -
Select statement having internal table in the wher clause...
Hi,
will all the entry from the internal i_crhd will be pased to the next select statement in the sample code below without looping? Thanks a lot!
REFRESH i_crhd.
SELECT objid vgwts
FROM crhd INTO CORRESPONDING FIELDS OF TABLE i_crhd
WHERE arbpl IN s_arbpl.
pulling the cost centre linked to the resource
IF sy-subrc EQ 0 AND i_crhd[] IS NOT INITIAL.
REFRESH i_crco.
SELECT kostl FROM crco
INTO CORRESPONDING FIELDS OF TABLE i_crco
FOR ALL ENTRIES IN i_crhd
WHERE objid = i_crhd-objid.
IF sy-subrc EQ 0.
do nothing.
ENDIF.
ENDIF.Hi,
The code looks fine..u can very well go ahead with the code...
Wht all other ABAPers said about FOR ALL ENTRIES is absolutely rite.
But i have a small suggestion...
Why cant u use a INNNER JOIN for those 2 queries...
like...
SELECT cr~objid
cr~vgwts
co~kostl
FROM crhd AS cr INNER JOIN
crco AS co
ON crobjid = coobjid
INTO TABLE i_crco
WHERE cr~arbpl IN s_arbpl.
Now in i_crco 3 fields will be thr
objid, vgwts, kostl.....this one can change as u wish...
Why i suggest not to ue FOR ALL ENTRIES is sometimes it is a performanc killer....in this code i feel this will do fine...
Please let me know if u feel not ok with this code...
Reward if found useful...
Regards,
ABAPer 007. -
Problem using 2 Fact tables with the same dimension
Hi,
I have noticed a very strange behaviour in Presentation Services / BI Administrator. I have 2 cubes (created in OWB) which are in the same business model, they are set up with foreign keys etc. and works as they should using them separately. Problem is (sometimes!) when I want to use the common dimension (Project) against both of the fact tables (Sales Order and Purchase Order).
Scenario 1:
If I use Project Id, Purchase Amount, Sales Amount I get either an amount in Sales Amount or in Purchase Amount, BUT if the Project Id starts with a letter (not starting with a number) it will show the correct amount for both Sales- and Purchase Amount.
Scenario 2:
I use Project Description (even followed by Project Id or not), Sales Amount, Purchase Amount I get the correct numbers for all projects. Project Description must come before Project Id or else it will not work.
I only noticed this problem when using both of the Fact tables since I want to compare Sales Amount and Purchase Amount in each Project. The Dimension for Project consist of Project, Sub Project and Activity and works fine. If I only use Sales Amount or Purchase Amount with Project Id I don't get this error. Only when both numbers are used.
I would be very happy if anyone have a good solution/explanation to this problem! Seems like could be something in the BI Server memory that goes wrong somewhere.The strange thing is that the results from the queries are correct running them in SQL Developer. This is one that works:
SELECT Project.Project saw_0, "- SalesOrderFact"."Sales Amount" saw_1, "- PurchaseOrderFact"."Purchase Amount" saw_2, REPORT_SUM(saw_1 BY ), REPORT_SUM(saw_2 BY ) FROM SalesOrder ORDER BY saw_0
SALES ORDER:
select T3032.PROJECT_DESCRIPTION as c1,
sum(T161.SALES_AMOUNT_LOCAL) as c2
from
DIM_PROJECT_V T3032,
CUBE_SALES_ORDER T161
where ( T161.DIM_PROJECT = T3032.DIMENSION_KEY )
group by T3032.PROJECT_DESCRIPTION
order by c1
PURCHASE_ORDER:
select T3032.PROJECT_DESCRIPTION as c1,
sum(T3020.TOTAL_BUY_AMOUNT) as c2
from
DIM_PROJECT_V T3032,
CUBE_PURCH_ORDER T3020
where ( T3020.DIM_PROJECT = T3032.DIMENSION_KEY )
group by T3032.PROJECT_DESCRIPTION
order by c1
And this will give the wrong result in Answers (correct in SQL..):
SELECT Project."Project Id" saw_0, "- SalesOrderFact"."Sales Amount" saw_1, "- PurchaseOrderFact"."Purchase Amount" saw_2, REPORT_SUM(saw_1 BY ), REPORT_SUM(saw_2 BY ) FROM SalesOrder ORDER BY saw_0
SALES_ORDER:
select T3032.PROJECT_KEY_NAME_ID as c1,
sum(T161.SALES_AMOUNT_LOCAL) as c2
from
DIM_PROJECT_V T3032,
CUBE_SALES_ORDER T161
where ( T161.DIM_PROJECT = T3032.DIMENSION_KEY )
group by T3032.PROJECT_KEY_NAME_ID
order by c1
PURCHASE_ORDER:
select T3032.PROJECT_KEY_NAME_ID as c1,
sum(T3020.TOTAL_BUY_AMOUNT) as c2
from
DIM_PROJECT_V T3032,
CUBE_PURCH_ORDER T3020
where ( T3020.DIM_PROJECT = T3032.DIMENSION_KEY )
group by T3032.PROJECT_KEY_NAME_ID
order by c1
As you can see the SQL look very familiar, and I cannot see anything in SQL that should be the cause of this error. I think the error must be in the BI Memory or something.
Any ideas? -
How to make a control table with the same number of rows of its itab
I'm creating a control table, but it always have the maximum number of lines possible.
How can I make it so that it has only the same number of rows of it's internal table?solved partialy with this:
MODULE locka_lin OUTPUT.
DATA: lin TYPE i.
DESCRIBE TABLE t_obj LINES lin.
table_con-lines = lin.
ENDMODULE. " OUTPUT
but it still doent work when lin = 0
any simple way to solve it on that case?
Edited by: RagnaRock on May 5, 2010 6:00 PM -
Reference all tables with the same name
If I have multiple worksheets that each have an identically structured table "Test", is it possible to create a formula in a cell of another worksheet that references the same range of cells in every table "Test"? So far I haven't found a way to reference cells in a table with an ambiguous name without having to prepend the worksheet name to the reference like so: 'Worksheet 1' :: Test :: B3:C4. What I want to be able to do is say Test :: B3:C4 and have the formula reference B3:C4 in all "Test" tables.
Thanks!You've picked the correct descriptive term. Such a reference would indeed be "ambiguous".
You might be able to reference a set of disconnected ranges of cells, but each range would have to be explicitly described.
You might be able to collect the values in the cells into a single array in a single table, then reference that array in your formula.
Regards,
Barry
PS: "Sheets" in Numbers have little in common with "Worksheets" in MS Excel. Using the Numbers vocabulary can help keep the distinction more clear, and avoid unwarranted expectations.
B. -
Dynamic Internal Table with the same name
Hey Guys
I have a question.
I know that we can create dynamic internal table taking a struct dynamically.
But I have 2 ques on the same subject.
1. Can we create an internal table based on a type that we have locally declared eg
types: begin of ty_demo.
var1(1) type c,
var2 type p,
end of ty_demo.
2. If an internal table is already declared based on the above type say data: i_tab type standard table of ty_demo.
If i need to enhance the struct of this internal table. Can i do that by dynamically redefining it based on a different structure but keepin the same name i_tab.
In a nut shell I cannot change the name of my itab but I want to enhance the structure.
I Hope I am clear.
Help will be greatly apprcieated.
Thanks
Sameerhai.
we can create an internal table based on a type that we have locally declared, but you have to use data instead of types like.
data: begin of ty_demo.
var1(1) type c,
var2 type p,
end of ty_demo.
check the example notes for dynamic itab .
Dynamic internal table is internal table that we create on the fly with flexible column numbers.
For sample code, please look at this code tutorial. Hopefully it can help you
Check this link:
http://www.****************/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
Sample code:
DATA: l_cnt(2) TYPE n,
l_cnt1(3) TYPE n,
l_nam(12),
l_con(18) TYPE c,
l_con1(18) TYPE c,
lf_mat TYPE matnr.
SORT it_bom_expl BY bom_comp bom_mat level.
CLEAR: l_cnt1, <fs_dyn_wa>.
Looping the component internal table
LOOP AT it_bom_expl INTO gf_it_bom_expl.
CLEAR: l_cnt1.
AT NEW bom_comp.
CLEAR: l_cnt, <fs_dyn_wa>, lf_mat.
For every new bom component the material data is moved to
temp material table which will be used for assigning the levels
checking the count
it_mat_temp[] = it_mat[].
Component data is been assigned to the field symbol which is checked
against the field of dynamic internal table and the value of the
component number is been passed to the dynamic internal table field
value.
ASSIGN COMPONENT c_comp_list OF STRUCTURE <fs_dyn_wa> TO
<fs_check>.
<fs_check> = gf_it_bom_expl-bom_comp.
ENDAT.
AT NEW bom_mat.
CLEAR l_con.
ENDAT.
lf_mat = gf_it_bom_expl-bom_mat.
Looping the temp internal table and looping the dynamic internal table
*by reading line by line into workarea, the materialxxn is been assigned
to field symbol which will be checked and used.
LOOP AT it_mat_temp.
l_nam = c_mat.
l_cnt1 = l_cnt1 + 1.
CONCATENATE l_nam l_cnt1 INTO l_nam.
LOOP AT <fs_dyn_table2> ASSIGNING <fs_dyn_wa2>.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa2> TO <fs_xy>.
ENDLOOP.
IF <fs_xy> = lf_mat.
CLEAR lf_mat.
l_con1 = l_con.
ENDIF.
Checking whether the material exists for a component and if so it is
been assigned to the field symbol which is checked against the field
of dynamic internal table and the level of the component number
against material is been passed to the dynamic internal table field
value.
IF <fs_xy> = gf_it_bom_expl-bom_mat.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
CLEAR l_con.
MOVE gf_it_bom_expl-level TO l_con.
CONCATENATE c_val_l l_con INTO l_con.
CONDENSE l_con NO-GAPS.
IF l_con1 NE space.
CONCATENATE l_con1 l_con INTO l_con SEPARATED BY c_comma.
CLEAR l_con1.
l_cnt = l_cnt - 1.
ENDIF.
<fs_check> = l_con.
l_cnt = l_cnt + 1.
ENDIF.
ENDLOOP.
AT END OF bom_comp.
At end of every new bom component the count is moved to the field
symbol which is checked against the field of dynamic internal table
and the count is been passed to the dynamic internal table field
value.
ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
<fs_check> = l_cnt.
INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
ENDAT.
ENDLOOP.
regards.
sowjanya.b -
Merge Two Tables with the same columns but different data
I have a table that has the following columns:
Current Table Definition
commonname
family
genus
species
subspecies
code
I have a number of entries that donât fit the current table definition â that is that they only have a common name or description and a code. These records donât actually represent a species but are needed for data entry because they represent an object that may be encountered in the study (Bare Ground â which isnât a species but would need to be recorded if encountered). So I would really like 2 tables:
Table 1 Miscellaneous
name
code
Table 2 Plant Species
commonname
family
genus
species
subspecies
code
I would like two tables so I can enforce certain constraints on my species table like requiring that the family, genus, species, subspecies combination is unique. I canât do this if I have all the âotherâ records that donât have a family, genus, species, or subspecies unless I put in a lot of dummy data into the fields to make each record unique. I donât really want to do this because these miscellaneous records really donât represent a specific species.
So â the problem is that while I want this data separate I will need to point a column from another table to the code column in both tables.
How is this best done? Table? View? Merge?Hi,
Actually you don't have to use scope refs. Sorry but I misunderstood you earlier. Here is a complete example that does exactly what you want. Notice how I added the constraint to the materialized view. Also notice when we try to insert a code in tbl3 that doesn't exist in the view, we get an error. HTH.
SQL> create table tbl1 (name varchar2(10), code varchar2(3) primary key);
Table created.
SQL> create table tbl2 (commonname varchar2(10), code varchar2(3) primary key);
Table created.
SQL> insert into tbl1 values ('n1','c1');
1 row created.
SQL> insert into tbl1 values ('n2','c2');
1 row created.
SQL> insert into tbl1 values ('n3','c3');
1 row created.
SQL> insert into tbl2 values ('name1','c1');
1 row created.
SQL> insert into tbl2 values ('name2','c2');
1 row created.
SQL> insert into tbl2 values ('name3','c3');
1 row created.
SQL> commit;
Commit complete.
SQL> create materialized view view1 as select name, commonname, tbl1.code from tbl1, tbl2 where tbl1.code = tbl2.code;
Materialized view created.
SQL> select * from view1;
NAME COMMONNAME COD
n1 name1 c1
n2 name2 c2
n3 name3 c3
SQL> create table tbl3 (code varchar2(3), record varchar2(1));
Table created.
SQL> alter table view1 add constraint view1pk primary key (code); -- <-Note how I added a constraint to the view
Table altered.
SQL> alter table tbl3 add constraint tbl3fk foreign key (code) references view1(code);
Table altered.
SQL> insert into tbl3 values ('c1','r');
1 row created.
SQL> insert into tbl3 values ('c99','r');
insert into tbl3 values ('c99','r')
ERROR at line 1:
ORA-02291: integrity constraint (RAJS.TBL3FK) violated - parent key not found
SQL> spool of;
-Raj Suchak
[email protected] -
Testing if two tables have the same structure
Hi,
I am looking for a tool that provides support for verifying whether two tables or databases schemas are same or not.
I want to input two sql script files:
1. one containing the create table for creating a table with name, id and email
2. other containing the create table for creating a table with name, id and an alter table statement for adding the email.
Now i have to test whether above two sql scripts will have the same impact on database.
This is just the simpler form of veru complex sql script file that i am working on.
Can DBunit do this and how.
Its very urgent. I will appreciate any help.Repeated thread at: more clarification about previous problem
Maybe you are looking for
-
on my windows 8.1 pc (i5 processor with 8GB ram) I can't get the automatic update voor CS4 master collection. I removed my panda antivirus and still can't automatically update. somebody any suggestion?
-
I have had my iPod Touch since christmas and it is now June. The version is 4.1 and it's the one with the camera. My previous cord worked fine and I never had any problems with iTunes or my iPod before. I lost my cord for about a month (actually I ha
-
So, a bunch of people have been using my computer lately, which I usually don't like, and this is why. Usually, when using Safari, lets say I have a google window open. When I hit tab, it goes from the google search area, to the address bar, to the g
-
No audio streaming music, yes audio everywhere else
Setup: - MacBook with WD MyBook1TB external for iTunes Library - Apple TV, component video to plasma TV & analog audio to stereo - Airport Express hooked up to a JBL OnStage iPod speaker set - iPhone with Remote app A couple nights ago I set the Appl
-
Can a PST file be treated as a lawsuit evidence ?
My company is having a lawsuit and asked to provide communication log which can only be found in an email of our employee's. This email has been downloaded to the local MS outlook 2007 and deleted on the server. But the judge doesn't accept the ema