Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2012
    Posts
    3

    Unanswered: Postgresql how to compare two column from two tables

    One of the column is used to store all the name and the other table column data is copied from text after optical character recognition. The input column data can match any row of the stored data. How do i do it?

    Thanks.

  2. #2
    Join Date
    Jan 2012
    Posts
    84
    What do you mean by "compare columns" ?

    Small example - suppose you have two tables with the following values:
    Code:
    column_name1
    --------------
    A
    A
    B
    C
    D
    
    column_name2
    --------------
    A
    B
    B
    B
    E
    F
    G
    H
    I
    J
    what should be a result of such compare ?
    Last edited by kordirko; 08-08-12 at 13:16.

  3. #3
    Join Date
    Aug 2012
    Posts
    3
    i mean
    Column_A
    -----------------------
    A
    B
    C
    D
    ------------------------
    After input the value into Column_B

    Column_B
    -------------------------
    D
    A
    E
    -------------------------


    as D exist in Column_A means match same for A however E is not in Column_A means it does not match.
    Hope you understand i meant.

    Thanks

  4. #4
    Join Date
    Jan 2012
    Posts
    84
    In other words, you want to retrieve all values from Column_B
    that exists in Column_a, and skip these values from B,
    that not exist in A, is this correct ?
    Code:
    SELECT column_b FROM table_B
    WHERE EXISTS(
       SELECT 1 FROM Table_A
       WHERE column_a = column_b
    )
    Another option:
    Code:
    SELECT column_b FROM table_B
    WHERE column_b IN (
        SELECT column_A FROM table_A
    )

  5. #5
    Join Date
    Aug 2012
    Posts
    3
    Thanks for the code. It works.
    However is this only for checking? and could not export the query data output into a new table?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •