Home » RDBMS Server » Server Administration » Any other ways of doing same?
Any other ways of doing same? [message #58535] Mon, 15 September 2003 20:11 Go to next message
Kapil
Messages: 145
Registered: May 2002
Senior Member
I have 2 tables, tab1 and tab2 both have ID
as the fields, in tab1 ID is not unique and has 225097
rows, and in tab 2 ID is unique and has 1392684 rows,
i want see if there is any id that is present in tab1
but not in tab2.
Well I am doing this but it takes for ever. actually never give me the out put.
1. select id from tab1 where id not in(select id from tab2);
2. select id from tab1 where not exists(select id from tab2 where tab2.id=tab1.id);
none of these queries works, i mean fast. i do have indexes on id on both the tables. is there any other way of doing same thing ?
Re: Any other ways of doing same? [message #58536 is a reply to message #58535] Mon, 15 September 2003 21:06 Go to previous messageGo to next message
Nihal
Messages: 1
Registered: September 2003
Junior Member
This will definitly be faster, I have used this in some of my queries with good result, Perform a outer join and filter the recs

For ef

select id from
tab1 a , tab2 b
where a.id = b.id (+)
and a.id is not null
and b.id is null

This will give u the id which is present in table a and not present in table b

I'll be interested in knowing how it goes,

Cheers

Nihal Singh
Re: Any other ways of doing same? [message #58538 is a reply to message #58536] Tue, 16 September 2003 00:45 Go to previous messageGo to next message
Rajarshi Dasgupta
Messages: 52
Registered: October 2001
Member
You may use....

select id from tab1
minus
select id from tab2

[[this should work quite fast]]

OR

select distinct id from tab1
minus
select id from tab2

Let me know whats the outcome and if this is what you required.
Re: Any other ways of doing same? [message #58544 is a reply to message #58536] Tue, 16 September 2003 06:11 Go to previous messageGo to next message
Kapil
Messages: 145
Registered: May 2002
Senior Member
This will give me all ids in tab1, but i want to know only the ids that are not in tab2 but present in table tab1.
Re: Any other ways of doing same? [message #58545 is a reply to message #58538] Tue, 16 September 2003 06:13 Go to previous messageGo to next message
Kapil
Messages: 145
Registered: May 2002
Senior Member
i tested with a small table, it works but i wonder, what scan it will do on million record tables.
thanks.
Re: Any other ways of doing same? [message #58546 is a reply to message #58545] Tue, 16 September 2003 07:16 Go to previous messageGo to next message
Rajarshi Dasgupta
Messages: 52
Registered: October 2001
Member
This SQL should run fine on big tables also. We handle tables containing 35-50 million records... and these SQLs work fine. Just try and lemme know the performance.

Try to 'ANALYZE' the tables before running the SQL.
Re: Any other ways of doing same? [message #58568 is a reply to message #58546] Wed, 17 September 2003 09:55 Go to previous message
Kapil
Messages: 145
Registered: May 2002
Senior Member
Excellentt!!!! it works gr88 thanks again.
Previous Topic: Remove tables from one tablespace to another
Next Topic: FATAL ERROR IN TWO-TASK SERVER: error = 12571
Goto Forum:
  


Current Time: Fri Sep 20 09:21:50 CDT 2024