Rails where two tables have the same data?

后端 未结 1 382
难免孤独
难免孤独 2021-01-29 10:55

I\'m trying to create a table in my view and populate it on some conditions.

I have two tables, Both have two columns inside, One columns called event_url

1条回答
  •  醉话见心
    2021-01-29 11:36

    You can easily achieve the result by using a LEFT OUTER JOIN from Table A to Table B, as described in this visual explanation.

    Specifically, what you want is:

    To produce the set of records only in Table A, but not in Table B, we perform the same left outer join, then exclude the records we don't want from the right side via a where clause.

    In your question is not clear how the tables are called, and how they relate each other. However, to achieve the result simply perform a join between the tables using the ActiveRecord join method

    TableA.joins('LEFT OUTER JOIN TableB on TableA.field = TableB.field')
    

    and select only the items where(TableB.id IS NULL).

    You'll have to adapt the example to your needs.

    0 讨论(0)
提交回复
热议问题