title: Subcategory entry based on another column - SQL
body: <p>I was wondering if it is possible in PostgreSQL to have a table that only accepts a column entry based on another column.</p>
  <p>For example, if the category is 1 or 3, there are no sub categories so subcategory cannot be entered. However, if category is entered as 2, then subcategory can be entered as A or B as in the example below. When I tried this below, it will not allow entries for category 1 or 3. Any help would be greatly appreciated, thanks!</p>
  <pre><code>CREATE TABLE some_table (
  
  category VARCHAR CHECK (category IN ('1','2','3'))
  
  subcategory VARCHAR CHECK (subcategory IN ('A','B') AND category = '2')
  
  )
  </code></pre>