Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL Select to compare two tables
Message
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01683376
Message ID:
01683384
Views:
23
In VFP I would create a DO WHILE loop and compare ALL columns in one table against the other table,
like this:
DO WHILE !EOF()
      SELECT TABLEB
      LOCATE TABLEB.COLUMN1 = TABLEA.COLUMN1 and TABLEB.COLUMN2 = TABLEA.COLUMN2 (and so on)
      IF FOUND()
          DELETE IN TABLEB
          DELETE IN TABLEA
     ENDIF
    SKIP IN TABLEA
ENDDO
The above is a pseudo code but maybe it will explain what I am trying to do.

>OK, I'm a little confused then. You initially said, "...just those rows that exist in one table but do not exist in another table."
>
>I took that to mean that a specific ID number was in Table A but not Table B. I guess maybe it boils down to, what is meant by "exists" in this context of the data?
>
>OK, if a single ID value (like 789) could exist as many rows in table A but not B....then you'd need to do a SELECT DISTINCT
>
>But if that doesn't help, then maybe I'm missing the question.
>
>
>>Again, thank you. The first SQL won't work since the value in ID_NUMBER could be the same for many rows. But some other columns are different. I will try your second approach. Although I thought that the SQL Select would have the actual column names.
>>
>>I am trying to figure out an example and right now I can't figure it ou.
>>
>>>Here's the simplest way....if all you want are the ID numbers in Table A that don't exist in Table B...
>>>
>>>SELECT ID_Number from TABLEA
>>>EXCEPT
>>>SELECT ID_Number from TABLEB
>>>
>>>Now, if you want "all the columns" from table A, you can do this...
>>>
>>>SELECT * FROM TABLEA WHERE ID_NUMBER IN
>>> (SELECT ID_Number from TABLEA INSIDE_A
>>> EXCEPT
>>> SELECT ID_Number from TABLEB INSIDE_B )
>>>
>>>Now....I'm assuming you don't have any NULL values for ID_Number (which, if it's a key identifier, you shouldn't).
>>>If you somehow do, you'd need to put a few IF NOT NULL statements....
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform