If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Compare 2 columns in 2 tables find difference

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-04, 06:39
Td04 Td04 is offline
Registered User
 
Join Date: Mar 2004
Posts: 52
Compare 2 columns in 2 tables find difference

I´ve been struggeling with a SQL query in an ASP page with a odbc to a database to try to find new records that comes into the first table(PLANID) and which are not yet in the second (PLANY) table which I update now and then. The columns are identical and have string values.
I´ve tried

SQL = "select PLANNUMMER From PLANID WHERE not [PLANNUMMER] = (select PLANNUMMER from PLANY)"

But it seems to only be able to get one record.
and:

SQL = "SELECT PLANNUMMER,COUNT(*) FROM PLANID MINUS SELECT PLANNUMMER,COUNT(*) FROM PLANY"

Does not seem to work either..

I would be thankful for any ideas
Thanks//Martin
__________________
"Never underestimate a large number of morons"
Reply With Quote
  #2 (permalink)  
Old 03-02-04, 07:11
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
there are three ways to do it:
PHP Code:
select PLANNUMMER 
  from PLANID 
 where PLANNUMMER not in
       
select PLANNUMMER 
           from PLANY 

PHP Code:
select PLANNUMMER 
  from PLANID 
 where not exists
       
select PLANNUMMER 
           from PLANY
          where PLANNUMMER 
PLANID.PLANNUMMER 
PHP Code:
select PLANID.PLANNUMMER 
  from PLANID 
left outer
  join PLANY
    on PLANID
.PLANNUMMER 
     
PLANY.PLANNUMMER
 where PLANY
.PLANNUMMER is null 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-02-04, 08:28
Td04 Td04 is offline
Registered User
 
Join Date: Mar 2004
Posts: 52
Talking Re: Compare 2 columns in 2 tables find difference

Thanks for the fast reply!
I am a newbee to PHP so.. do I have to use PHP or can it be done in ASP, php is not yet installed on the server..
Or can I just use the PHP script tag in the ASP page without changing the .asp suffix of the page to the PHP suffix
something like:

<script language="php">
/* SQL = select PLANNUMMER
from PLANID
where PLANNUMMER not in
( select PLANNUMMER
from PLANY )*/
</script>

Thanks//M
__________________
"Never underestimate a large number of morons"
Reply With Quote
  #4 (permalink)  
Old 03-02-04, 09:02
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
i am sorry if my response was confusing

in most discussion forums, [code] ... [ /code ] tags are used to delineate code which is shown using a normal sized, fixed-width font

in this forum, [ code ] is small sized, proportional font

therefore i use [ php ] ... [ /php ] to display code, because it displays in the desired font


you can run those queries directly from ASP
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 03-02-04, 09:11
Td04 Td04 is offline
Registered User
 
Join Date: Mar 2004
Posts: 52
Talking

ahaa! now I see, That was kind of funny..
Thanks again!//Martin
__________________
"Never underestimate a large number of morons"
Reply With Quote
  #6 (permalink)  
Old 03-02-04, 11:08
Td04 Td04 is offline
Registered User
 
Join Date: Mar 2004
Posts: 52
It works great! one more question though.. is any of these sql statements quicker than the other?, I am working on a big database with thousands of records in it so the server goes very tired
//M
__________________
"Never underestimate a large number of morons"
Reply With Quote
  #7 (permalink)  
Old 03-02-04, 11:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
theoretically they should all be the same

but hey, in theory, theory and practice are the same, but in practice, they often aren't
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On