Count total records in 2 tables
Hello,
I am using this query
select count(*) from table1, table2) to get the total number of records in those 2 tables. Actually I have only 7 records in both the tables, but I get 15. What could be the problem?
Also I need to find out another query where in I can find out which table is giving a particular record. e.g table1 has firstname,lastname and table2 has firstman,lastman. I need to know that firstname has come from tabl1 and firstman has come from table2.
Please help.
Thanks
Well, if I'm not misstaken the difference between
UNION and UNION ALL is that UNION ALL will include
duplicates while UNION will ignore the duplicates.The UNION clause forces all rows returned by each
portion of the UNION to be sorted and merged and
duplicates to be filtered before the first row is
returned. A UNION ALL simply returns all rows
including duplicates and does not have to perform any
sort, merge or filter. It is much more efficient.
(Although the performance factor may be irrelevant in
the OP's situation - the issue of duplicate rows
isn't)And what did I say?
Asuming the OP does not have duplicates within each
table (when he/she would really violate relational
database theory) Why do you assume that? Why would this violate
relational database theory?If you don't have a primary key, it sure does. I don't have my C J Date book here, but this looks like an accurate transcript of C F Codd's twelve rules a relational database must obay: http://engr.smu.edu/~fmoore/notes/12rules.htm Look at number 2...
there will not be any difference between the twoUNION "versions".
That is correct. I just didn't want to change that
part of the code ( String s1 = rs.getString(2)...)
since the OP asked about the database query.i wasn't referring to the OP, hence the 'ps' and 'for
anyone doing this sort of thing in Oracle' and 'if you
tend to use the column name version of getString()'
Yes, you are again correct. I just explained why I wrote what I wrote.
Similar Messages
-
Counting duplicate records in a table
Hi,
I have to display duplicate records in a table,but the table name and column should be passed dynamically(In procedure). Please let me know the query for this.Try this one, is used to find the duplicate value from table
Type: I
SELECT * FROM employees e1 WHERE rowid> (SELECT min(rowid)
FROM employees e2 WHERE e1.department_id=e2.department_id);
Type: II
SELECT * FROM my_table t1 WHERE EXISTS (SELECT 'x' FROM my_table t2
WHERE t2.key_value1 = t1.key_value1
AND t2.key_value2 = t1.key_value2
AND t2.rowid > t1.rowid);
Type: III
SELECT count(*), empn FROM empmast_dum
GROUP BY empn HAVING count(*) >1 ORDER BY empn;
Type: IV
SELECT dep, name,net,RANK() OVER (PARTITION BY dep ORDER BY net) rank
FROM empmast_dump
WHERE dep=04;
Type: V
SELECT empn FROM empmast_dump
WHERE empn NOT IN(SELECT MIN(empn)
FROM empmast_dump GROUP BY NAME;
I have to display duplicate records in a
table,but the table name and column should be passed
dynamically(In procedure). Please let me know the
query for this.When you need to pass table name dynamically in your procedure ,
just enter table name as substitution variable or bind variable, if u want to know about
this, read here
venki
http://venki-hb.blogspot.com/2008/02/basic-sql-query-tips.html -
To display total records in a table through Go URL
Hi All,
Can anyone give me the solution how to display all the records of a table through Go URL. Actually according to the documentation provided by the oracle or the stuff in the blogs, We can write Go URL to display all the records in a table in two methods.
1) To change the properties of a table and use the basic Go URL.
2) Adding Action=Scroll&P5=-1&ViewID=go~Table to the Go URL.
First one is not a solution in our case, According to our scenario we should not change table properties because If we change the properties and display the whole records in one page... it will impact the performance.
Coming to the second, we tried to append this part in the report Go URL. But It gave Assertion Failure Error.
Anybody please provide a solution how to write a Go URL to get all the records in the table.Hi All,
Can anyone give me the solution how to display all the records of a table through Go URL. Actually according to the documentation provided by the oracle or the stuff in the blogs, We can write Go URL to display all the records in a table in two methods.
1) To change the properties of a table and use the basic Go URL.
2) Adding Action=Scroll&P5=-1&ViewID=go~Table to the Go URL.
First one is not a solution in our case, According to our scenario we should not change table properties because If we change the properties and display the whole records in one page... it will impact the performance.
Coming to the second, we tried to append this part in the report Go URL. But It gave Assertion Failure Error.
Anybody please provide a solution how to write a Go URL to get all the records in the table. -
I am new to the Oracle environment and I am trying to find a quick way to get the total number of records loaded into a table. Is there any command you can use to verify this? I know a log file can be created when loading a file, but I do not see a record count displayed in this file. Thank you in advance for your help.
Hi Melissa,
The simplest way to do this is to issue a SELECT statement on the table you have loaded. This can be achieved by issuing the following command:
SELECT COUNT(*) FROM table_name;
where the table_name is the name of the table you have just loaded.
Secondly, you can obtain the number of records loaded by turning your FEEDBACK parameter on before prior to loading. At the end of a successful load, the number of records created will be displayed, assuming that your are loading from one table to another.
For more info, please refere to the SQL*PLUS reference manual.
Thanks,
John
null -
How to count same record in a table
i have :
table A: id - name - code
but now i have so much same record by name, i want select all record by name have same name > 2, and count it . pls help meTry:
WITH CTE AS (
SELECT Color, COUNT(*) OVER (PARTITION BY Color) AS Freq,
ROW_NUMBER() OVER (PARTITION BY Color ORDER BY (SELECT 1) ) AS RN
FROM Production.Product WHERE Color is not null)
SELECT Color, Freq FROM CTE WHERE RN=1
AND Freq > 1 ORDER BY Color;
Black 93
Blue 26
Multi 8
Red 38
Silver 43
Silver/Black 7
White 4
Yellow 36
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
Count of records/rows in a Table
Hi
This could be a basic question , but i don't have an idea how to do that .
Could you please tell me , how get an count of records/rows in a specific table ?
Thank you
Lukesb92075 wrote:
It takes time to get count of records if the table size is hugCan YOU count to 1000000000000000000 as quickly as you count to 10?????????????????????????
If it takes you longer to count many things, why do you expect Oracle to do better than you?Really??
Let's try some counts and see.
First off, let's count a few 1000 rows.
SQL> set timing on
SQL> select count(*) from all_objects;
COUNT(*)
45045
Elapsed: 00:00:17.08So 17 seconds for 45,000 rows.
Now if you're logic is correct, counting let's say a few billion rows, should take an hour? Perhaps more?
Here's what I see on one of my larger tables:
SQL> select count(*) from daily_xxxxxxx;
COUNT(*)
2569780329
Elapsed: 00:00:10.03Oops... it is faster.
Get a clue!I hereby sincerely apologise that my database does not adhere to your fine logic that says it should take a few hours - I will speak disapprovingly to the CBO for allowing the 2nd select count (on the same database) to be faster than the 1st select count. I will even use the backchannel to inform Larry that this is not acceptable.
Of course, this is assuming that you do not have your head stuck up somewhere and are indeed correct that it takes a "+looooonnngggg+" time to count lots of rows.
!http://smileyicons.net/smilies/actions1.gif! -
How to get count as 0 for records not in table
Hi All,
I have requirement where I need count of records in the table based on ids. Example query below
SELECT empid ,
nvl(COUNT(id), 0) empcount
FROM employee
WHERE empid IN(1, 2, 4, 5)
GROUP BY empid
In the table only record for "empid=2" is present so I get count 1 for it. But with it I should get count as 0 for non existing records. Expecting below output
empid | empcount
1 | 0
2 | 1
4 | 0
5 | 0
Appreciate your help and Thanks in advance.
Regards.
Ashishe.g.
SQL> select column_value deptno, count (deptno)
from emp, table (sys.odcinumberlist (10, 20, 100))
where deptno(+) = column_value
group by column_value
DEPTNO COUNT(DEPTNO)
10 3
20 5
100 0
3 rows selected. -
How to get a total record count before grouping?
I need to group a report on a formula that does roughly the following:
[record count] / ( [total record count] / 20 )
What this acheives is to label each record with a number of 1 - 20 which I want to group on. Getting this figure is the easy part, what is not working is the fact that I cannot group from a formula that is calculated after grouping. I overcame a portion of this by using "Whilereadingrecords" (rather than "count", running totals, or while printing records) to acheive a record count.
I can't figure out how to get a total record count done before grouping. Is there a way to do this with "WhileReadingRecords"?? Is this even possible?
Thanks
JohnHi John,
The order of how Crystal does things dictates the order of which features you can use. Crystal has a two pass method. In the first pass it does things like passing the query, grouping, summarizing. In the second pass it does formulas, formatting, etc.
Unfortunately Crystal does the Grouping before summarizing so what you want to do can't be done in Crystal. The best way to get around this to either create a SQL Command or view/stored procedure that will do the summarizing for you. Then in the report you can use it.
Hope this helps,
Brian -
Count total number of record of table with deletion from archiving object
Does anyone know is there any SAP standard program to count the total number of record of the table with deletion from Archiving Object and display in repprt?
Not sure of the question. Are you looking to get the sql "select count(*) from table" from using the TopLink expression framework or are you getting that SQL already and want something else?
If you are looking just to get the count from a table/class, you can use a ReportQuery:
ReportQuery rquery = new ReportQuery(ClassToQueryOn.class);
rquery.addCount(); //equivalent to count(*);
session.executeQuery(rquery);
You can use a report query to return data instead of objects, and use selection criteria just like a normal read query.
Best Regards,
Chris -
How to find total count of records in a cursor
Aassume below is the cursor i defined
cursor c1 is select * from emp;
now, i want to find the total count of records in this cursor using an existing function etc., using one line statement.
FYI: c1%rowcount is always giving 0, so i cant rely on this.
Any thoughts, please share.
Thanks in advance.I am just showing this to show how to get the rowcount along with the cursor, if the program has so much gap of between verifying the count(*) and opening the cursor.
Justin actually covered this, he said, oracle has to spend some resources to build this functionality. As it is not most often required, it does not makes much sence to see it as a built-in feature. However, if we must see the rowcount when we open the cursor, here is a way, but it is little bit expensive.
SQL> create table emp_crap as select * from emp where 1 = 2;
Table created.
SQL> declare
2 v_cnt number := 0;
3 zero_rows exception;
4 begin
5 for rec in (select * from (select rownum rn, e.ename from emp_crap e) order by 1 desc)
6 loop
7 if v_cnt = 0 then
8 v_cnt := rec.rn;
9 end if;
10 end loop;
11 if v_cnt = 0 then
12 raise zero_rows;
13 end if;
14 exception
15 when zero_rows then
16 dbms_output.put_line('No rows');
17 end;
18 /
No rows
PL/SQL procedure successfully completed.
-- Now, let us use the table, which has the data
SQL> declare
2 v_cnt number := 0;
3 zero_rows exception;
4 begin
5 for rec in (select * from
6 (select rownum rn, e.ename from emp e)
7 order by 1 desc)
8 loop
9 if v_cnt = 0 then
10 v_cnt := rec.rn;
11 dbms_output.put_line(v_cnt);
12 end if;
13 end loop;
14 if v_cnt = 0 then
15 raise zero_rows;
16 end if;
17 exception
18 when zero_rows then
19 dbms_output.put_line('No rows');
20 end;
21 /
14
PL/SQL procedure successfully completed.Thx,
Sri -
How to get the total record count in ODI
Hi
I have the interface the are file to DB.
The format is like this..
HEADER
DETAIL
TRAILER
Now will write the contains of file to DB,
But i have to insert the total count ie numberof record written from file to DB in my Trailer record.
can you tell me how can i get the total count of records in file and write it to trailer?
Also, I want the interface to rollback the data if something fails will loading the data from file., ie. if there are 100 records in file and 50 got transfer and something fails i want to rollabck the 50 records from DB.???
Thanks :)Hi
You can design a flow for Full load flow and incremental flow from flat file to Table.
Create a table at target database like.. (create table with last_execution and palce the V_FULL_LOAD value and LAST_EXECUTION_DT columns in last_execution table)
Add faltfile as table in model, create a variable as V_FULL_LOAD and make sure that the default values is 01-01-1900
Create one more variable like V_LAST_EXECUTION_DATE (in this variable write a case statement that if V_FULL_LOAD value is 'Y" then full load should happen and same time you should check that V_FULL_LOAD column is balnk then write insert statment else write update statement to update last_execution_dt column, similar for 'N')
please provide your *personal mail ID*, i will send a doc file realted to your query.
we have to tables present in work repository (SNP_STEP and STEP_LOG tables) using tables we can get how many records are inserted/updated and we can find how many records are not transfer and gor error.
Thanks
Phani -
How to receive a part of cursor together with total count of records
Hello for all!
I have table with 5 millions of records. This table has varchar2 field.
I need look into this table by this field with using LIKE '%something%'. I.e. I need search by free substring in varchar2 field.
Because my table has serious record count then this query runs during 5-20 seconds and can return serious amount of records (for example 300.000 records).
I don't want to receive 300.000 records in the user program which runs on user desktop computer. I want receive records by page. I.e. by chunks with 100-200 records.
I can use following query:
select * from
(select rownum rn, t1.* from table1 t1 where field1 like '%something%' order by field2)
where rn between 100 and 200
This query can return only needed records from total cursor.
But in this case I don't know total records quanity. But I should show to user total quantity of pages!
I can run query twice. I.e. first time I can run "select count(*) ", next time I can "select * ". But it means that Oracle should process two queries instead of one. This is not good desigion.
Please suggest me something useful for solving this problem.
Thank you,
Best regards,
EugenyI can use following query:
select * from
(select rownum rn, t1.* from table1 t1 where field1 like '%something%' order by field2)
where rn between 100 and 200That is not correct.
http://asktom.oracle.com/pls/ask/f?p=4950:8:5368894803981003723::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:127412348064
But in this case I don't know total records quanity. But I should show to user total quantity of pages!That is not a good idea.
http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:127412348064#14136093079164 -
How to count total number of records in mYSQL through JSP ??
hi
i want method to count total number of records in table.
it was there rs.count() method in VB .
But what about JSP , i used MYSQL database.
tell me solution please...
thanks...
remember JSP - total record count for mySQLhello mr.
i don't want ur suggestion ok
i know that site.
no need to give suggestion if u don't give code.
its better to give proper reply instead of making a
comment in forum.
next time take care
He was perfectly justified in that remark. I have given you the information you need, nicely, twice. But I, and noone else here is going to do your work for you. We will point you in the direction you need to be looking, but we are not going to give code. If you attempt to code something yourself, and it doesn't work, then post the code you tried, and we may make some corrections to it. Then again, with the attitude you've shown so far we probably will not. But one thing no one here will do, is do your work. Especially not for free.
Now, if you are not willing to sit down, and look at the suggestion that has already been made, and attempt to use it. Then continue wasting your time, but go away and stop wasting our time. -
Record count per page , total record count per report in BI Publisher
hi,
In Oracle BI Publisher tool , can you please tell me how to display total record count of a report ? as well as how to display record count per page ?
Thanks for your help
Regards
Gayathricheck inbox. forwarded the updated template
-
How to count records from 2 tables and show in RDLC Report
hi all,
its being a one day searching for the solution but No Luck.
I have two SQL tables tblstudetail and tblfeereceiptdetail.
i just want to count records from both tables and show in RDLC report.
I tried SQl Query Like This:
select a.session, a.course,
Count(CASE a.ADstatus WHEN 'OK' THEN 1 ELSE 0 END ) AS Admission,
Count(CASE s .I_receiptstatus WHEN 'OK' THEN 1 ELSE 0 END) AS Feeprint
from
tblstudetail a
FULL join
tblfeereceiptdetail s on s.studentID = a.studentID
where a.session = '2015' AND s.Fsession = '2015' AND a.adcat = 'Regular'
GROUP BY a.session,a.course
ORDER by a.course
The result Show the Same Value in Both columns
Session Course Admission FeeDetail
2015 B.A. I 275 275
2015 B.A. II 307 307
2015 B.A. III 255 255
2015 B.Sc. I 110 110
2015 B.Sc. II 105 105
2015 B.Sc. III 64 64
Actully I want to Count How many ADMISSION have been Taken(FROM tblstudetail) and How many FEE RECEIPT have been Print (From tblfeereceiptdetail).
please guide me for this as soon as possible.
thanks in advance...I am counting 'OK' in both the table columns I.e 'ADstatus' in tblstudetail and 'feereceiptstatus' in tblfeereceiptdetail
please suggest me
Maybe you are looking for
-
i'm trying to update from 3.2, but when I try to transfer the download to the application folder I get the message, "The operation can't be completed because you don't have permission to access some of the items."
-
Hi, I am using the 'for-each' to map a nodeset to a nodeset that has a maxOccurs="3" in the XSD schema. Is there a way to limit the 'for-each' to only map 3 values and stop after that? Regards
-
IMovie audio problems when burning in Toast 6
Hi, i've tried to burn an imovie project in idvd 5 but i get 'the error #-1 was reported' like most people have been and i've tried loads of things suggested to fix it with no joy. I then sent the imovie project to toast titanium 6 where it burned fi
-
What is the required file for update?
I've recently (and unfortunately) installed the new iPod update 1.2. When I try to update the songs on my iPod, I get a message that tells me the iPod can't be updated because the required file is locked. Any idea what file that may be and how I can
-
How to check for Optional Oracle 10gR2 components installed?
Hi How can I get a list of all optional oracle database components/features installed (some of them may require additional license)? I was going through list of directory objects in a database and I spotted "ORACLE_OCM_CONFIG_DIR" in one of the datab