Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
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:
  #1  
Old August 26th, 2005, 08:11 AM
dangerousjohnny dangerousjohnny is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 109 dangerousjohnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 18 sec
Reputation Power: 6
SQL Query help

Hello,
Can someone pls help me w/ the following query? I'm trying to select all the records in the LIST table who have both a matching Postal Code + Address in the CLIENTS table.


UPDATE CLIENTS
SET DNS='YES'

WHERE PC IN (SELECT MAIL_CODE_UP FROM LIST WHERE PC=MAIL_CODE_UP)

AND

AD1 IN (SELECT ADDRESS1 FROM LIST WHERE ADDRESS1=AD1);

COMMIT;

Reply With Quote
  #2  
Old August 26th, 2005, 08:23 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
But PC corresponds to MAIL_CODE or MAIL_CODE_UP in LIST table?

Reply With Quote
  #3  
Old August 26th, 2005, 08:32 AM
dangerousjohnny dangerousjohnny is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 109 dangerousjohnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 18 sec
Reputation Power: 6
Sorry, it should have read MAIL_CODE_UP, I fixed. But the problem is, it matches more than it should, for example in CLIENTS, PC 'M1N0P0' AD1 'PO BOX 21' will match LIST MAIL_CODE_UP'M1N0P0' ADDRESS1'PO BOX 789'

Reply With Quote
  #4  
Old August 26th, 2005, 08:40 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278
Shouldn't it be something like:
sql Code:
Original - sql Code
  1.  
  2. UPDATE CLIENTS
  3. SET DNS='YES'
  4. WHERE CLIENTS.PC=LIST.MAIL_CODE_UP
  5. AND
  6. CLIENTS.AD1 = LIST.ADDRESS1;

Reply With Quote
  #5  
Old August 26th, 2005, 08:54 AM
dangerousjohnny dangerousjohnny is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 109 dangerousjohnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 18 sec
Reputation Power: 6
I keep getting an invalid column reference error . Don't I have to select the LIST table first or something?

Reply With Quote
  #6  
Old August 26th, 2005, 09:05 AM
pabloj's Avatar
pabloj pabloj is offline
Modding: Oracle MsSQL Firebird
Dev Shed God 6th Plane (7500 - 7999 posts)
 
Join Date: Jun 2001
Location: Outside US
Posts: 7,815 pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level)pabloj User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 2 Months 3 Weeks 1 Day 14 m 37 sec
Reputation Power: 278


sql Code:
Original - sql Code
  1. UPDATE CLIENTS
  2. SET DNS='YES'
  3. WHERE PC IN (SELECT MAIL_CODE_UP FROM LIST WHERE CLIENTS.PC=LIST.MAIL_CODE_UP AND LIST.ADDRESS1=CLIENTS.AD1)
  4. AND
  5. AD1 IN (SELECT ADDRESS1 FROM LIST WHERE CLIENTS.PC=LIST.MAIL_CODE_UP AND LIST.ADDRESS1=CLIENTS.AD1);

or
sql Code:
Original - sql Code
  1.  
  2. UPDATE CLIENTS, LIST
  3. SET DNS='YES'
  4. WHERE CLIENTS.PC=LIST.MAIL_CODE_UP
  5. AND
  6. CLIENTS.AD1 = LIST.ADDRESS1; 

don't have Oracle at hand, sorry.

Reply With Quote
  #7  
Old August 26th, 2005, 09:20 AM
dangerousjohnny dangerousjohnny is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 109 dangerousjohnny User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 25 m 18 sec
Reputation Power: 6
thank you very much, that worked!

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > SQL Query help


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 6 hosted by Hostway