Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old April 23rd, 2004, 03:54 AM
YuLing YuLing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 44 YuLing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to YuLing
Using minus??

Hi..

I've got these 2 tables

t1
|Emp_id|Name|Plant|
|-A001-|ABCD|--A--|
|-A002-|BCDE|--A--|
|-A003-|CDEF|--A--|
|-A004-|DEFG|--A--|
|-A005-|EFGH|--A--|

t2
|Emp_id|Name|Plant|
|-B001-|ZYXW|--B--|
|-B002-|YXWV|--B--|
|-B003-|XWVU|--B--|
|-B004-|ABCD|--B--|
|-B005-|BCDE|--B--|

I want to find the records in t1 that is not existing in t2

If i use MINUS;
Code:
select * from t1
minus
select * from t2

it will return back all records from t1, even the records that exists in t2 as i think only the Name column can be compare.
Example:
|Emp_id|Name|Plant|
|-A001-|ABCD|--A--|
|-A002-|BCDE|--A--|
|-A003-|CDEF|--A--|
|-A004-|DEFG|--A--|
|-A005-|EFGH|--A--|

When i try using;
Code:
select name from t1
minus
select name from t2

it return back the name in t1 that is not in t2..which is just a part of wat i want to do.
Example:
|Name|
|CDEF|
|DEFG|
|EFGH|

Is there a way to return all the columns in t1 and not only just the name?

Example:
|Emp_id|Name|Plant|
|-A003-|CDEF|--A--|
|-A004-|DEFG|--A--|
|-A005-|EFGH|--A--|

Should i be using MINUS or something else such as NOT EXISTS...but i do not really know how to do the NOT EXISTS thing. Can anyone help me figure out a way to do solve this??

Thanks

YuLing

Last edited by YuLing : April 23rd, 2004 at 03:58 AM.

Reply With Quote
  #2  
Old April 23rd, 2004, 08:05 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Try that:

SELECT * from t1
WHERE name not in (SELECT name from t2)
/

Reply With Quote
  #3  
Old April 26th, 2004, 02:50 AM
YuLing YuLing is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 44 YuLing User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Send a message via ICQ to YuLing
Thanks for ur help again

But why does the number of rows selected are different when i do this to double check...

select name from t1
minus
select name from t2;

-------------------------------------

select name from t1
where name not in (select name from t2)


The first query return more rows than the second one.

Reply With Quote
  #4  
Old April 26th, 2004, 10:43 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
Your query is just fine, suppose to produce the same number of record(s).

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Using minus??


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway