Sqlite Create Table with Check column from other table I have two tables:
position
CREATE TABLE IF NOT EXISTS position(
  id_position INTEGER PRIMARY KEY AUTOINCREMENT,
  name TEXT NOT NULL,
  min REAL NOT NULL CHECK (min &gt; 0),
  max REAL CHECK (max &gt; 0),
);

min, max links to salary
employee
CREATE TABLE IF NOT EXISTS employee (
  id_employee INTEGER PRIMARY KEY AUTOINCREMENT,
  id_position INTEGER NOT NULL,
  name TEXT NOT NULL,
  last_name TEXT NOT NULL,
  data_of_birth TEXT NOT NULL CHECK (DATE(data_of_birth) IS NOT NULL AND data_of_birth &lt; DATE('now','localtime')),
  salary REAL NOT NULL CHECK (salary &gt;= position.min AND salary &lt;= position.max),
  FOREIGN KEY(id_stanowisko) REFERENCES stanowisko(id_stanowisko)
);

But check in salary column doesn't work. I have an error no such column: position.min.
Any solution?
Looking up a value from another table would require a subquery, but the documentation says:


  The expression of a CHECK constraint may not contain a subquery.


There is no such restriction on a trigger's WHERE clause:

CREATE TRIGGER employee_salary_check
BEFORE INSERT ON employee
WHEN NEW.salary &lt; (SELECT min FROM position WHERE id_position = NEW.id_position)
  OR NEW.salary &gt; (SELECT max FROM position WHERE id_position = NEW.id_position)
BEGIN
  SELECT RAISE(FAIL, "invalid salary");
END;