OiO.lk Blog SQL Get all missing records with conditions on other two related tables
SQL

Get all missing records with conditions on other two related tables


Suppose three tables:

Table A
has_many :table_b

Table B
belongs_to :table_a
belongs_to :table_c

Table C
has_many :table_b

Table B and Table C have each a boolean attribute has an boolean attribute called "active"

How do I write a SQL statement or Active record expression where I get all the Table A records that don’t have

  1. any Table B records with active saved as true and
  2. and if it has, that which are not associated with any Table C with the active attribute saved as true?



You need to sign in to view this answers

Exit mobile version